Using: GNU bash, version 4.2.24(1)-release (i686-pc-linux-gnu)
I ignore a signal using trap command on an interactive shell. I expect that signal to remain ignored in the script started from the same shell. However, I find disposition of that signal reset to default, even though trap command in the script shows that signal is ignored.
I am not sure if this is the right behavior. Please help.
Step 1 - Ignore the signal by typing the following command on an interactive shell
----------
$ trap '' SIGXFSZ
Step 2 - Given below is a script that starts a sleep in the background and then sends the signal to that sleep to test if the signal terminates the sleep or not.
---------
$ cat test_1.sh
trap
sleep 30&
sleep 1
pid=$!
kill -s SIGXFSZ $pid
sleep 1
kill -0 $pid && echo "sleep survived the signal" && exit
echo "sleep was terminated by the signal"
$
Step 3 - Even though the disposition of the signal was set to ignore in the Step 1 (and first line of the output of script confirms that), yet, the sleep is terminated by the signal. Is it right?
----------
$ ./test_1.sh
trap -- '' SIGXFSZ
./test_1.sh: line 8: 8674 File size limit exceeded(core dumped) sleep 30
./test_1.sh: line 9: kill: (8674) - No such process
sleep was terminated by the signal
$