On Saturday, November 11, 2023, Corto Beau <corto.beau@laposte.net> wrote:
Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -g -O2
uname output: Linux zinc 6.6.1-arch1-1 #1 SMP PREEMPT_DYNAMIC Wed,
08 Nov 2023 16:05:38 +0000 x86_64 GNU/Linux
Machine Type: x86_64-pc-linux-gnu
Bash Version: 5.2 Patch
Level: 21
Release Status: release
Description:
Hi,
I would like to suggest a new shell option to ensure child
processes are automatically killed when the parent dies.
Right now, it's already possible to emulate this feature by
setting a trap to kill all child processes on exit (trap "kill 0"
EXIT), but obviously it doesn't work if the process is terminated
by a signal that cannot be caught (like SIGKILL).
On Linux, it can be done by setting the PR_SET_PDEATHSIG flag to
propagate the parent termination signal to the child, regardless
of whether the signal can be caught or not.
The rationale for this feature is that scripts spawning background
processes to listen to various events (udev events, window manager
events, etc) often leave orphan processes behind when terminated
forcefully.
I've attached a proof-of-concept patch.
I think it'd make more sense to implement this as a loadable builtin.
--
Oğuz