Why does sleep, when run in a shell script, ignore SIGINT?
11
votes
1
answer
2779
views
When I run
sleep
manually, and then kill -INT
it, sleep exits immediately. For example:
$ /bin/sleep 60 &
4002356
$ kill -INT 4002356
+ 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.
Asked by mpb
(1831 rep)
May 31, 2021, 05:55 AM
Last activity: May 31, 2021, 07:27 AM
Last activity: May 31, 2021, 07:27 AM