On Thu, Aug 31, 2017 at 02:52:58PM +0100, Richard W.M. Jones wrote: > > On Thu, Aug 31, 2017 at 07:59:41AM -0500, Eric Blake wrote: > > Rich Jones just taught me about Linux' prctl(PR_SET_PDEATHSIG), which > > allows you to run a helper executable that will automatically be killed > > if its parent process dies. I'm trying to figure out if coreutils > > should provide support for that API via any of its existing wrapper > > utilities (in fact, it sounds somewhat like the opposite of nohup - > > instead of spawning a child process that survives the shell's death, we > > want to be able to spawn a child process that automatically cleans > > itself up on the shell's death). Or maybe we make a new wrapper > > utility. However, since the functionality is currently Linux-only, I'm > > also wondering if coreutils is still a good choice for this > > functionality, or if we should pursue exposing it in some other package > > of useful shell utilities. > > My idea (I'll leave it to someone else to implement) would be some > kind of cleanup wrapper for shell scripts, like: > > autocleanup [-s TERM] someprog &
But beware: that Linux octopus systemd will probably get in the way. It has been killing 'nohup' sessions for about a year. Look at systemd-run(1) for some ways round this. > If the main script exits, someprog gets killed automatically. No need > for traps etc. > > Note that ‘PR_SET_PDEATHSIG’ is passed through exec to non-setuid > processes so this is fairly simple to implement. For setuid it would > fail silently, and testing for setuid might be problematic or racy I > suppose. > > Of course this is all Linux-only. Do other kernels implement anything > like this? We could use it for nbdkit: > > https://github.com/libguestfs/nbdkit/commit/370b554fb38be7360815af70d5e0175842c451c6 -- Alain Williams Linux/GNU Consultant - Mail systems, Web sites, Networking, Programmer, IT Lecturer. +44 (0) 787 668 0256 http://www.phcomp.co.uk/ Parliament Hill Computers Ltd. Registration Information: http://www.phcomp.co.uk/contact.php #include <std_disclaimer.h>
