Under which conditions does the OS kill child processes when their parent exits?
0
votes
0
answers
48
views
I am new to Linux and attempting to understand its management of child processes. I have read that child processes do not necessarily exit when their parent does, but I have observed mostly contrary behavior (e.g. child processes generally exiting when their parent is killed).
A simple example can be generated via
sudo sleep 60
, which results in a sudo
process and a child process executing its command argument (sleep 60
). Sending SIGTERM to the sudo
process results in both processes exiting. Notably, the result is the same when sending SIGKILL to the sudo
process. Since SIGKILL cannot be caught, I suspect that the OS does kill child processes, but I do not know under which conditions.
One potential mechanism for this is process groups/sessions. However, kill
is not called with the negation of sudo
's PID/PGID in the example above, and sudo setsid sleep 60
results in the same behavior (despite setting the SID and PGID of the child process to its own PID).
Another is the OS sending SIGHUP to processes associated with a common controlling terminal when the latter is closed. However, I again observe the same behavior when executing commands via a system service, in which case the relevant processes have no controlling terminal (verified via ps
).
Can anyone explain this behavior?
Asked by user49539
(1 rep)
Mar 21, 2025, 05:52 AM