mesard@bbn.com (Wayne Mesard) (02/18/88)
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@bbn.com
cjc@ulysses.homer.nj.att.com (Chris Calabrese[rs]) (02/18/88)
In article <20917@bbn.COM>, mesard@bbn.com (Wayne Mesard) writes: > 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); If the parent of this deamon is the shell, it should receive the hangup signal upon the termination of the shell through logging out. This should make it unnessary to commit suicide at all, as it's done for you. Of course, you can always catch the signal and do some additional processing. Chris Calabrese AT&T Bell Laboratories ulysses!cjc
mouse@mcgill-vision.UUCP (der Mouse) (03/13/88)
In article <10096@ulysses.homer.nj.att.com>, cjc@ulysses.homer.nj.att.com (Chris Calabrese[rs]) writes: > In article <20917@bbn.COM>, mesard@bbn.com (Wayne Mesard) writes: >> During execution [a daemon] occasionally checks to see if the parent >> is still around, and commits suicide if it isn't: > If the parent of this deamon is the shell, More likely, its parent is now init, but its parent used to be the shell. That is, when it was started, it forked and exited to put itself into the background. > it should receive the hangup signal upon the termination of the shell > through logging out. Huh? As far as I can tell, my processes never get HUPs when the shell exits. Certainly not if they're running. (If they are stopped, the shell warns, but if you insist, it will go ahead and exit. It then does send some signal to the stopped jobs, but I don't recall what signal. But none of that happens to running jobs.) der Mouse uucp: mouse@mcgill-vision.uucp arpa: mouse@larry.mcrcim.mcgill.edu