On Wednesday, April 10, 2013 02:43:12 PM Ilya Basin wrote:
> Hi.
> I have a script that creates some background tasks.
> I want the whole tree to be killed by Ctrl-C.
"tree"? If a script isn't coordinating with its subprocesses manually, then
the only real guaranteed way to kill a process and all its descendants
recursively is to use something like Linux cgroups or BSD jails. A tree of
descendants isn't normally maintained by an OS for each process. You would
have to go through every running process and walk the PPID chain to build a
tree, and this will always be racy.
> There's a requirement that the script process and its children must
> belong to the same process group. This is why I can't enable job
> control.
>
> I don't want to use 'trap', because it adds complexity.
>
trap is the standard (only) way to handle signals in shell. They don't have to
be complicated.
http://mywiki.wooledge.org/ProcessManagementhttp://mywiki.wooledge.org/SignalTrap
--
Dan Douglas