logout

D. Richard Hipp drh at duke.cs.duke.edu
Tue Feb 5 09:52:16 AEST 1991


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.

Off the top of my head...

  system("ps -x | awk '$1!=\"PID\"{print $1}' | sort -n |"
         "while read name; do kill -9 $name; done;");

The above will kill off every process associated with your tty.  That
should probably be sufficient to log you out.  Notice, however, that
this technique is not especially efficient, nor is it very portable.
In fact, I can think of a pathological case where it won't even work.
(Specifically, if the process kills off itself before it gets your
login shell.)  Perhaps the creative use of options to "ps", or another
filter in the pipe can overcome this bug.

You also might try:

  kill(getppid(),9)

This will kill off the parent of the process running, which in most
cases will be your shell, but is by no means guarenteed to be.

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)

All of these solutions are, of course, specific to UNIX.



More information about the Comp.lang.c mailing list