Suppose I am running the following example saved as hello.sh
#!/bin/bash
hello() {
echo "hello"
}
trap "hello" INT
sleep 100
echo "end"
and in shell I start hello.sh. After 1 second I press Ctrl-C.
Please treat sleep as any long-run process that I started.
Here are my questions:
- When
SIGINTis generated, is it delivered tosleepdirectly or to the shell script? - If it is the second, can I let
sleephas a chance to handle theSIGINTand do not propagate to its parenthello.sh? - If it is the first, what is the status of
sleepafter thehellofunction is finished?
My tests made me feel that the following occurred in order
sleepstarted to runhello.shreceived the signal- function
hellostarted to run - function
hellofinished echo "end"started to run- the script exits.
But at which stage the sleep process exits and because of what (e.g. the SIGINT stopped the sleep process?)