Unix & Linux
bash subshell sighup
Updated Mon, 15 Aug 2022 11:37:17 GMT

How can I stop a child process of a subshell (as per SIGSTOP) before the subshell exits?

In bash, when running ( sleep 123 &), the sleep 123 process will continue running, when the subshell exits. How can I stop the sleep 123 process before its parent subshell exits?

I'm trying to see if the sleep 123 process will be terminated, because of receiving SIGHUP and SIGCONT. I am looking for an example for Is SIGHUP sent to this orphaned process, and why doesn't it terminate? and Does kernel sending SIGHUP to a process group that becomes orphaned and contains a stopped process terminate all the processes by default?


This will show the behaviour youre trying to illustrate:

(sleep 60 & kill -STOP $!)

This puts sleep in the background, then stops it. It then gets killed by SIGHUP when the subshell exits.

Signals can interrupt some system calls; see the signal(7) manpage (in particular the Interruption of system calls and library functions by signal handlers section). The system calls used by sleep in particular are interrupted when a signal handler is invoked, and this is documented in sleep(3).