in reply to Re^2: automatically killing all child processes created in a script
in thread automatically killing all child processes created in a script

This does not wait for all children to finish. It processes multiple children from the same SIG CHLD signal if they are "ready". If the parent "dies", then you as a child eventually get this CHLD signal and you get removed from the process table. This is a non-blocking situation, that's what WNOHANG does - it doesn't "hang up" waiting for anybody. If say 3 of 20 children have CHLD signal at the same time, then you have to process those 3 children at once. After that, then the other 17 is a different story. So no, this will not "hang" and wait for all children to finish. This just says, "hey at least one and maybe more than one children" are in CHLD signal state". "At least one" does not mean "all", and it doesn't mean wait for all children to be in CHLD signal state!

Ok, then if you are launching servers that spawn other child processes, then you should keep track of the PID's or names of those things. If you have permission level that allows you to kill that server, then its children will also be killed if you have right signal handling installed.

  • Comment on Re^3: automatically killing all child processes created in a script

Replies are listed 'Best First'.
Re^4: automatically killing all child processes created in a script
by JavaFan (Canon) on Aug 22, 2009 at 00:52 UTC
    Ok, it doesn't wait for children to die. But the code you present is code that runs when children die. That's not what the OP asked. The OP asked to *kill* the children. And its children.
      This is code that runs in each child when the parent dies. In other words, when the parent dies, the children are so upset about it that they commit suicide. It could very well be that the parent doesn't even know how many children that it has.

      Killing the parent causes the children and their kids to "suicide". I hope that you can forgive my thinking that, hey "kill the parent which kills the whole family", and then make a new parent which makes new kids sort of thinking... I guess that is grossly immoral, but it does have a certain simplistic logic to it.

      The alternative isn't much better: tell the parent to keep track of all of the family (instead of the OS doing that) and then ask the parent to kill off the "clan". This is an "OS like" supervisory function. That is certainly possible. I see no technical problem with a strategy like that being implemented.

      I guess, paraphrasing the ancient saying: there are many ways to Rome.