bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: FEATURE REQUEST : shell option to automatically terminate child proc


From: Corto Beau
Subject: Re: FEATURE REQUEST : shell option to automatically terminate child processes on parent death
Date: Sat, 11 Nov 2023 21:32:44 +0100
User-agent: Mozilla Thunderbird

Do you mean something like a "fork_noreparent" builtin that would call make_child and set PDEATHSIG afterwards, or a "noreparent" builtin that the child would have to call ? I do agree that it wouldn't make sense to implement the later as a shell option, but this particular use of prctl is subject to a race condition that can only be avoided by comparing the PID of the parent before calling fork and after calling prctl (in case the process got reparented before setting PDEATHSIG), because checking for ppid = 1 is not enough on systems like Linux where the process might have been reparented by a subreaper.

On 11/11/2023 20:49, Oğuz wrote:
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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]