Home » Questions » Computers [ Ask a new question ]

When a Python process is killed on OS X, why doesn't it kill the child processes?

When a Python process is killed on OS X, why doesn't it kill the child processes?

I found myself getting very confused a while back by some changes that I found when moving Python scripts from Linux over to OS X...

Asked by: Guest | Views: 88
Total answers/comments: 1
Guest [Entry]

"On Linux, when you kill a parent the child gets sent a SIGHUP which will generally kill it unless it was meant to stay alive as a daemon in which case it will trap sighup. (I think this is why one usually uses SIGHUP to tell a daemon to refresh itself, since it's conveniently always trapped).

On Mac OS X I can't find documentation, but it appears that no SIGHUP gets sent. As a result, the child process is orphaned, and its new parent is the grandparent.

The way you deal with this is you send the kill signal to the process group of the parent, not the parent process itself. This will nuke all the children and grand children as well with one caveat. If any child process does a setpgrp() or setsid() then it escapes the process group membership. It will not get the kill sent to its old process group. Usually one need not worry about the latter since it's usually intentional when used to achieve that purpose."