Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What would cause a SIGTERM to not propagate to child processes?

I have a process on Linux that starts up 20 child processes via fork. When I kill the parent process, it will often kill all of the child processes, but sometimes it doesn't kill all of them, and I'm left with some orphaned processes. This isn't a race condition on startup, this is after the processes have been active for several minutes.

What sort of things could cause SIGTERM to not propagate to some child processes properly?

like image 496
steve8918 Avatar asked Dec 29 '15 20:12

steve8918


1 Answers

There is no automatic propagation of signals (SIGTERM or otherwise) to children in the process tree.

Inasmuch as killing a parent process can be observed to cause some children to exit, this is due to ancillary effects -- such as SIGPIPEs being caused when the child attempts to read or write to a pipeline with the dead parent on the other side.

If you want to ensure that children are cleaned up when your process receives a SIGTERM, install a signal handler and do it yourself.

like image 140
Charles Duffy Avatar answered Sep 20 '22 13:09

Charles Duffy