in reply to Child process dies

In general the OS will provide the parent notification when the child goes away automatically; what you're trying to do is bass ackwards from the way things normally work on most *NIXen. You may get better answers if you explain what you're trying to do by this rather than seeking a mechanism you think will accomplish it.

Replies are listed 'Best First'.
Re^2: Child process dies
by Anonymous Monk on Jan 05, 2007 at 15:27 UTC
    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.
      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.

      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

      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