killing daemons

Wayne Mesard mesard at bbn.com
Thu Feb 18 12:48:48 AEST 1988


I recently wrote a program that runs in background for the duration
of a login session.  When it starts it gets its parent process id:

    ppid = getppid();
    if (fork())
	exit(0);

During execution it occasionally checks to see if the parent is
still around, and commits suicide if it isn't:

    if (kill(ppid, 0))
	exit(0);

Since this statement gets executed every couple of minutes, the
background job is guaranteed to go away shortly after the parent
(i.e. the login shell) does.

My question is ==> Is there a better / more direct / more socially
acceptable way to reap background processes?  This method seems
like asking wheat to cut itself down as the combine drives by.


(unsigned char *) Wayne_Mesard()		MESARD at bbn.com



More information about the Comp.unix.questions mailing list