I have a program that spawns many instances of other programs. I want to have a clean way to kill them after timeout, even if they spawn subprocesses, sometimes accidentally daemonize, etc.
Right now I use process group approach: each instance is run in its own process group, and I signal the entire group when I want to kill it. And it seems to work fine so far.
However, it's very easy to create a new process group and thus escape from my control. Those programs are not inherently malicious (so they won't try to do this on purpose), but can be very sloppily written. They could be Python scripts, ugly shell scripts, things like that.
So my question is, when exactly process groups are usually created? According to my observations, interactive shells create them, but non-interactive don't. For instance, are they any kind of advanced shell constructs that tend to create new process groups even in non-interactive scripts?
setpgrp
call), and also introduces dependency on systemd, which is not everywhere. Anyway, finding the best process control mechanism would be a topic of another question that I might ask later, once I weigh all available options. – WGH Aug 31 '16 at 21:49