When I run sleep manually, and then kill -INT it, sleep exits immediately. For example:
$ /bin/sleep 60 &
[1] 4002356
$ kill -INT 4002356
[1]+ Interrupt /bin/sleep 60
$ ps -C sleep
PID TTY TIME CMD
$
However, when I do the same thing in a shell script, sleep ignores the SIGINT. For example:
set -o xtrace
echo
/bin/sleep 10 &
child="$!"
/bin/sleep 0.1
ps -C sleep
kill -TERM "$child" # SIGTERM
/bin/sleep 0.1
ps -C sleep
wait "$child" # will return immediately
echo
/bin/sleep 10 &
child="$!"
/bin/sleep 0.1
ps -C sleep
kill -INT "$child" # SIGINT
/bin/sleep 0.1
ps -C sleep
wait "$child" # will wait for 9.8 seconds
Why/how does sleep ignore SIGINT when I run sleep inside a shell script?
I get the same behavior with dash and bash. My kernel is Linux 5.4.0.
set +mseems very relevant. Try withset -mand compare. (2) In my Debian the phenomenon does not occur inposh; this shell does not supportset -m/set +m.dash -m,sleepexits upon receiving SIGINT, as expected. I'm reading your answer now, and pondering how a child process can inherit a signal handler across an exec(). I was not aware that was possible.