Here's a script that generates a script that will try to catch all signals. The script it generates (sigcatcher.sh) outputs the name of the caught signal before exiting.
#!/bin/sh
# generate a shell function for each and every available signal.
/bin/kill -l | tr ' ' '\n' |
while read signal; do
cat <<END_OF_FUNCTION
handle_$signal () {
echo "Caught $signal"
exit
}
trap 'handle_$signal' $signal
END_OF_FUNCTION
done >sigcatcher.sh
echo 'echo "$$"; sleep 600' >>sigcatcher.sh
On my system (OpenBSD), /bin/kill -l generates a list of available signals on one line, that's why the tr is there to break it up.
The generated script will look something like this:
handle_HUP () {
echo "Caught HUP"
exit
}
trap 'handle_HUP' HUP
handle_INT () {
echo "Caught INT"
exit
}
trap 'handle_INT' INT
(etc.)
And it will be finished off with
echo "$$"; sleep 600
It outputs its PID and sleeps for 10 minutes.
You run it like this:
$ sh ./sigcatcher.sh >sigcatcher.out
Then you close the window, and then you inspect sigcatcher.out.
I don't run X Windows, but when I kill the tmux pane that this script is running in, I get "Caught HUP" in the output file.
strace?SIGHUP; howeverSIGHUPis what I see when testing this. Lacking a script to demonstrate the problem, there's nothing to test.