logout

logout

Post by Geoff Cla » Sat, 09 Feb 1991 00:03:38



[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]


>    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.


[stuff deleted]

Quote:>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.

--

UniSoft Limited, London, England.   Tel: +44 71 729 3773   Fax: +44 71 729 3273

 
 
 

logout

Post by Geoff Cla » Tue, 12 Feb 1991 21:53:27



>If you want to kill processes which have been run with "nohup", use
>SIGKILL instead of SIGHUP.

Oops, bit of finger trouble there.  Of course, I meant "use SIGTERM
instead of SIGHUP".
--

UniSoft Limited, London, England.   Tel: +44 71 729 3773   Fax: +44 71 729 3273