From: Francis Cianfrocca Date: 2007-05-28T21:27:21+09:00 Subject: Re: Killing sons (Linux) ------=_Part_46549_23202166.1180355235014 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 5/28/07, Ohad Lutzky wrote: > > > Now, my system also allows a 'kill' command, intended to stop the job in > progress. This has been causing me a lot of trouble, and I suddenly > (after quite a while the system has been in production, how embarassing) > realized why - the PID I'm keeping is of the daemon fork. Killing it > doesn't kill all of its sons - it causes bash to get reparented to init! > > Any idea of a clean, quick way to fix this? Make your parent process the leader of its own process group with setpgid(0,0). When you fork, add each child to the parent's process group with setpgid(0, getppid()). If you fork subchildren, make sure they get added to the same process group. Now, to send a signal to the whole group, send it to (0 - pid), where pid is that of the parent. If you want them all to die without killing the leader, use a signal whose default behavior is terminate-process and ignore it in the parent. ------=_Part_46549_23202166.1180355235014--