logout
Geoff Clare
gwc at root.co.uk
Fri Feb 8 02:03:38 AEST 1991
[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 at irie.ais.org> garath at 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 at romeo.cs.duke.edu> drh at 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 <gwc at root.co.uk> (Dumb American mailers: ...!uunet!root.co.uk!gwc)
UniSoft Limited, London, England. Tel: +44 71 729 3773 Fax: +44 71 729 3273
More information about the Comp.unix.questions
mailing list