in reply to Re: Child process dies
in thread Child process dies

What I want to do is following: one parent process is creating lisening server process. This parent is forking a child which is "log maintainer" - it logs all the activity of parent/child processes into file and maintains that file size. Log maintainer (child process) is active all the time. What I want to complish is when I kill parent I want child to die instantly as well. I do not want to kill 2 processes in order to shut the functionality. Now I did this by means of two techniques: 1. child periodically checks if parentpid exists. If there is no parent pid it exists ; or 2. When parent is killed with INT signal - there is a signal handler for upon receiving the INT - it will kill child and then parent. Those aproaches are with flaws: 1. I want child instantly killed when parent is killled and not to check periodicly! 2. What if parent is killed by other means than INT signal? -Dejan.

Replies are listed 'Best First'.
Re^3: Child process dies
by imp (Priest) on Jan 05, 2007 at 15:37 UTC
    SIGKILL does not allow for graceful shutdown as the process is never notified that it should stop - the kernel just removes it. You should only be sending a SIGKILL if the process is hung and will not shut down by any other means.

    Read man 7 signal for more information on signaling.

Re^3: Child process dies
by johngg (Canon) on Jan 05, 2007 at 16:02 UTC
    Let the parent kill the child but install more than one handler, not just INT. You definitely want TERM and possibly QUIT. There's no point in installing a handler for KILL as imp and jettero point out.

    Cheers,

    JohnGG

Re^3: Child process dies
by roboticus (Chancellor) on Jan 05, 2007 at 22:21 UTC
    Okay, then, swap your processes' parentage. Make the "log maintainer" be the parent, and have it spawn the "doit" job. Then, when the doit job exits, the log maintainer job will notice it, and you can have it shut down gracefully.....

    Roboticus