Xref: utzoo comp.lang.c:36021 comp.unix.questions:28602 Path: utzoo!mnetor!tmsoft!torsqnt!lethe!yunexus!ists!helios.physics.utoronto.ca!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!olivea!decwrl!elroy.jpl.nasa.gov!sdd.hp.com!spool.mu.edu!uunet!mcsun!ukc!pyrltd!root44!gwc From: gwc@root.co.uk (Geoff Clare) Newsgroups: comp.lang.c,comp.unix.questions Subject: Re: logout Message-ID: <2598@root44.co.uk> Date: 7 Feb 91 15:03:38 GMT References: <+W9+Y=A@irie.ais.org> <665707935@romeo.cs.duke.edu> Followup-To: comp.unix.questions Organization: UniSoft Ltd., London, England Lines: 46 [I have cross-posted to comp.unix.questions and directed followups there as this topic is UNIX specific, and not appropriate for comp.lang.c] In article <+W9+Y=A@irie.ais.org> garath@ais.org (Belgarath) writes: > > Hi. I've created a generic menu program for new users on our system. >I have everything working now except for a logout option. Is there a way to >have to program kill all processes/jobs and then log the user out or do they >need to quit the program and then exit? > Please respond via e-mail. Thanks. >P.S. How could I have had this expire in, say 10 days? I don't see expire at >the top as one of the options I could fill in. In <665707935@romeo.cs.duke.edu> drh@duke.cs.duke.edu (D. Richard Hipp) writes: [stuff deleted] >I`ve never tried it, but according to my man-pages, the following should >do a more complete job of killing everyone off: > killpg(getpgrp(0),9) This works, but killpg() is not very portable. On all UNIX systems I'm familiar with, the same effect can be obtained by using kill() with a process ID of 0. Also, signal 9 (SIGKILL) is not a good choice of signal, because it cannot be caught and so the processes will not be able to clean up. As a rule SIGKILL should only be used as a last resort to kill processes that otherwise refuse to die. In the case under discussion (simulating a logout), the appropriate signal is SIGHUP, which is what the processes would receive when a user logs off leaving background jobs running. So the best solution is kill(0, SIGHUP); or from a shell kill -1 0 If you want to kill processes which have been run with "nohup", use SIGKILL instead of SIGHUP. -- Geoff Clare (Dumb American mailers: ...!uunet!root.co.uk!gwc) UniSoft Limited, London, England. Tel: +44 71 729 3773 Fax: +44 71 729 3273