Reputation: 11
this is a script, the name is test.sh
#!/bin/bash
cleanup(){
echo "Caught SIGINT ..."
exit 1
}
trap 'cleanup' 3
while :;do
echo "a"
sleep 3
done
if I run nohup ./test.sh &
in linux bash directly , it can catch kill -3 PID signal ,
but if I write nohup ./test.sh &
in a script file that name is go.sh) ,and I run go.sh , an then test.sh can't catch kill -3 PID signal
how can I write the go.sh script to make sure test.sh catch -3 signal ?
Upvotes: 1
Views: 778
Reputation: 20688
kill -3
(SIGQUIT
) would not work. According to bash's manual:
When bash is interactive, in the absence of any traps, it ignores
SIGTERM
(so thatkill 0
does not kill an interactive shell), andSIGINT
is caught and handled (so that the wait builtin is interruptible). In all cases, bash ignoresSIGQUIT
. If job control is in effect, bash ignoresSIGTTIN
,SIGTTOU
, andSIGTSTP
.
Upvotes: 1