If I have the following shell script
sleep 30s
And I hit Ctrl+C when the shell script is running, the sleep dies with it.
If I have the following shell script
sleep 30s &
wait
And I hit Ctrl+C when the shell script is running, the sleep continues on, and now has a parent of 1.
Why is that? Doesn't bash propagate Ctrl+C to all the children?
EDIT: If I have the following script
/usr/bin/Xvfb :18.0 -ac -screen 0 1180x980x24 &
wait
where I am spawning a program, this time Ctrl+C on the main process kills the Xvfb process too.
So how/why is Xvfb different from sleep?
In the case of some processes I see that they get reaped by init, in some cases they die. Why does sleep get reaped by init? Why does Xvfb die?
zshignores that (unhelpful) requirement, so inzsh, you can work around it with(trap - INT; sleep 30) &. In other shells, you'd need to usezsh -c 'trap - INT; exec sleep 30' &or useperlor other things that don't have that silly requirement. – Stéphane Chazelas Oct 30 '18 at 17:10bash, the problem can be worked around by starting the command as acoprocinstead of with&:{ coproc sleep 30 < /dev/null >&4 4>&-; } 4>&1which doesn't seem to ignore SIGINT/SIGQUIT... – Stéphane Chazelas Oct 30 '18 at 17:18