Does the following way
$ (sleep 123 &)
$ jobs
$
remove the process group of sleep 123
from bash's job control? What is the difference between the above way and disown
then?
Note that the sleep 123
process is still in the same process group led by the now disappearing subshell, and in the same process session as the interactive shell, so share the same controlling terminal.
Does not being in the shell's job control explain that the sleep 123
process will not receive any signal (including SIGHUP) sent from the bash process?
Thanks.
Best Answer
Yes, it removes it, so to speak.
When you run a
(...)
subshell from an interactive bash script, a new process group (job) is created, which becomes the foreground process group on the terminal, and in the case where the subshell contains any command terminated by&
, (eg.sleep 3600 &
) that command will be started in the very same foreground process group, withSIGINT
andSIGQUIT
ignored and its input redirected from/dev/null
). See here for some links to the standard.When the
(...)
subshell exits, that foreground job is removed from the shell's jobs table, and thesleep 3600
command will continue to run outside of the control of the shell.This is quite different from the case where
(sleep 3600 &)
is run from a non-interactive script with no job control, where everything (the main shell, its(...)
subshell, and any "background" commands (foo &
), inside or outside the(...)
subshell) is run in the same process group.