Peng Yu
2018-11-16 21:55:14 UTC
Hi,
I made the following test case to show what signals will cause EXIT.
It seems that
- SIGKILL directly kill the process without triggering EXIT.
- SIGCHLD does not trigger EXIT.
- SIGSTOP and SIGCONT do not trigger EXIT. (Test cases not shown as
the two signals are kind of special.)
- SIGINT and SIGQUIT are ignored as they are not sent from the same terminal.
So, other than these signals, all the rest signals cause EXIT. Is my
conclusion correct? Some of the conclusion is counter-intuitive. For
example, what is the reason to EXIT when SIGWINCH is triggered?
Could anybody let me know what signals will result in EXIT? Thanks.
$ cat script.sh
#!/usr/bin/env bash
# vim: set noexpandtab tabstop=2:
mkdir -p /tmp/trapls/pid
mkdir -p /tmp/trapls/log
echo "$$" > "/tmp/trapls/pid/$1.txt"
while IFS= read -r s
do
done < <(trap -l | awk -v OFS=$'\t' -e '{ for(i=2;i<=NF;i+=2) { print
$i } }'; echo EXIT)
sleep 10 &
wait "$!"
$ cat main.sh
#!/usr/bin/env bash
# vim: set noexpandtab tabstop=2:
set -v
rm -rf /tmp/trapls/pid
rm -rf /tmp/trapls/log
for s in $(trap -l | awk -v OFS=$'\t' -e '{ for(i=2;i<=NF;i+=2) {
print $i } }' | grep -v SIGSTOP | grep -v SIGCONT; echo EXIT)
do
./script.sh "$s" &
done
wait
$ cat main_kill.sh
#!/usr/bin/env bash
# vim: set noexpandtab tabstop=2:
while IFS= read -r s
do
pid=$(< "/tmp/trapls/pid/$s.txt")
echo "$(date):$s"
kill -s "$s" "$pid"
done < <(trap -l | awk -v OFS=$'\t' -e '{ for(i=2;i<=NF;i+=2) { print
$i } }' | grep -v SIGSTOP | grep -v SIGCONT; echo EXIT)
$ ./main.sh
$ ./main_kill.sh # run in a terminal different from the terminal in
which .main.sh runs.
Fri Nov 16 15:29:40 CST 2018:EXIT
Fri Nov 16 15:29:40 CST 2018:SIGHUP
Fri Nov 16 15:29:40 CST 2018:SIGINT
Fri Nov 16 15:29:40 CST 2018:SIGQUIT
Fri Nov 16 15:29:40 CST 2018:SIGILL
Fri Nov 16 15:29:40 CST 2018:SIGTRAP
Fri Nov 16 15:29:40 CST 2018:SIGABRT
Fri Nov 16 15:29:40 CST 2018:SIGEMT
Fri Nov 16 15:29:40 CST 2018:SIGFPE
Fri Nov 16 15:29:40 CST 2018:SIGKILL
Fri Nov 16 15:29:40 CST 2018:SIGBUS
Fri Nov 16 15:29:40 CST 2018:SIGSEGV
Fri Nov 16 15:29:40 CST 2018:SIGSYS
Fri Nov 16 15:29:40 CST 2018:SIGPIPE
Fri Nov 16 15:29:40 CST 2018:SIGALRM
Fri Nov 16 15:29:40 CST 2018:SIGTERM
Fri Nov 16 15:29:40 CST 2018:SIGURG
Fri Nov 16 15:29:40 CST 2018:SIGTSTP
Fri Nov 16 15:29:40 CST 2018:SIGCHLD
Fri Nov 16 15:29:40 CST 2018:SIGTTIN
Fri Nov 16 15:29:40 CST 2018:SIGTTOU
Fri Nov 16 15:29:40 CST 2018:SIGIO
Fri Nov 16 15:29:41 CST 2018:SIGXCPU
Fri Nov 16 15:29:41 CST 2018:SIGXFSZ
Fri Nov 16 15:29:41 CST 2018:SIGVTALRM
Fri Nov 16 15:29:41 CST 2018:SIGPROF
Fri Nov 16 15:29:41 CST 2018:SIGWINCH
Fri Nov 16 15:29:41 CST 2018:SIGINFO
Fri Nov 16 15:29:41 CST 2018:SIGUSR1
Fri Nov 16 15:29:41 CST 2018:SIGUSR2
$ for f in /tmp/trapls/log/*.txt; do echo "==> $f <=="; cat "$f"; done
==> /tmp/trapls/log/EXIT.txt <==
Fri Nov 16 15:29:46 CST 2018:EXIT
==> /tmp/trapls/log/SIGABRT.txt <==
Fri Nov 16 15:29:40 CST 2018:SIGABRT
Fri Nov 16 15:29:40 CST 2018:EXIT
==> /tmp/trapls/log/SIGALRM.txt <==
Fri Nov 16 15:29:40 CST 2018:SIGALRM
Fri Nov 16 15:29:40 CST 2018:EXIT
==> /tmp/trapls/log/SIGBUS.txt <==
Fri Nov 16 15:29:40 CST 2018:SIGBUS
Fri Nov 16 15:29:40 CST 2018:EXIT
==> /tmp/trapls/log/SIGCHLD.txt <==
Fri Nov 16 15:29:46 CST 2018:EXIT
==> /tmp/trapls/log/SIGEMT.txt <==
Fri Nov 16 15:29:40 CST 2018:SIGEMT
Fri Nov 16 15:29:40 CST 2018:EXIT
==> /tmp/trapls/log/SIGFPE.txt <==
Fri Nov 16 15:29:40 CST 2018:SIGFPE
Fri Nov 16 15:29:40 CST 2018:EXIT
==> /tmp/trapls/log/SIGHUP.txt <==
Fri Nov 16 15:29:40 CST 2018:SIGHUP
Fri Nov 16 15:29:40 CST 2018:EXIT
==> /tmp/trapls/log/SIGILL.txt <==
Fri Nov 16 15:29:40 CST 2018:SIGILL
Fri Nov 16 15:29:40 CST 2018:EXIT
==> /tmp/trapls/log/SIGINFO.txt <==
Fri Nov 16 15:29:41 CST 2018:SIGINFO
Fri Nov 16 15:29:41 CST 2018:EXIT
==> /tmp/trapls/log/SIGINT.txt <==
Fri Nov 16 15:29:46 CST 2018:EXIT
==> /tmp/trapls/log/SIGIO.txt <==
Fri Nov 16 15:29:41 CST 2018:SIGIO
Fri Nov 16 15:29:41 CST 2018:EXIT
==> /tmp/trapls/log/SIGKILL.txt <==
==> /tmp/trapls/log/SIGPIPE.txt <==
Fri Nov 16 15:29:40 CST 2018:SIGPIPE
Fri Nov 16 15:29:40 CST 2018:EXIT
==> /tmp/trapls/log/SIGPROF.txt <==
Fri Nov 16 15:29:41 CST 2018:SIGPROF
Fri Nov 16 15:29:41 CST 2018:EXIT
==> /tmp/trapls/log/SIGQUIT.txt <==
Fri Nov 16 15:29:46 CST 2018:EXIT
==> /tmp/trapls/log/SIGSEGV.txt <==
Fri Nov 16 15:29:40 CST 2018:SIGSEGV
Fri Nov 16 15:29:40 CST 2018:EXIT
==> /tmp/trapls/log/SIGSYS.txt <==
Fri Nov 16 15:29:40 CST 2018:SIGSYS
Fri Nov 16 15:29:40 CST 2018:EXIT
==> /tmp/trapls/log/SIGTERM.txt <==
Fri Nov 16 15:29:40 CST 2018:SIGTERM
Fri Nov 16 15:29:40 CST 2018:EXIT
==> /tmp/trapls/log/SIGTRAP.txt <==
Fri Nov 16 15:29:40 CST 2018:SIGTRAP
Fri Nov 16 15:29:40 CST 2018:EXIT
==> /tmp/trapls/log/SIGTSTP.txt <==
Fri Nov 16 15:29:40 CST 2018:SIGTSTP
Fri Nov 16 15:29:40 CST 2018:EXIT
==> /tmp/trapls/log/SIGTTIN.txt <==
Fri Nov 16 15:29:40 CST 2018:SIGTTIN
Fri Nov 16 15:29:40 CST 2018:EXIT
==> /tmp/trapls/log/SIGTTOU.txt <==
Fri Nov 16 15:29:40 CST 2018:SIGTTOU
Fri Nov 16 15:29:40 CST 2018:EXIT
==> /tmp/trapls/log/SIGURG.txt <==
Fri Nov 16 15:29:40 CST 2018:SIGURG
Fri Nov 16 15:29:40 CST 2018:EXIT
==> /tmp/trapls/log/SIGUSR1.txt <==
Fri Nov 16 15:29:41 CST 2018:SIGUSR1
Fri Nov 16 15:29:41 CST 2018:EXIT
==> /tmp/trapls/log/SIGUSR2.txt <==
Fri Nov 16 15:29:41 CST 2018:SIGUSR2
Fri Nov 16 15:29:41 CST 2018:EXIT
==> /tmp/trapls/log/SIGVTALRM.txt <==
Fri Nov 16 15:29:41 CST 2018:SIGVTALRM
Fri Nov 16 15:29:41 CST 2018:EXIT
==> /tmp/trapls/log/SIGWINCH.txt <==
Fri Nov 16 15:29:41 CST 2018:SIGWINCH
Fri Nov 16 15:29:41 CST 2018:EXIT
==> /tmp/trapls/log/SIGXCPU.txt <==
Fri Nov 16 15:29:41 CST 2018:SIGXCPU
Fri Nov 16 15:29:41 CST 2018:EXIT
==> /tmp/trapls/log/SIGXFSZ.txt <==
Fri Nov 16 15:29:41 CST 2018:SIGXFSZ
Fri Nov 16 15:29:41 CST 2018:EXIT
I made the following test case to show what signals will cause EXIT.
It seems that
- SIGKILL directly kill the process without triggering EXIT.
- SIGCHLD does not trigger EXIT.
- SIGSTOP and SIGCONT do not trigger EXIT. (Test cases not shown as
the two signals are kind of special.)
- SIGINT and SIGQUIT are ignored as they are not sent from the same terminal.
So, other than these signals, all the rest signals cause EXIT. Is my
conclusion correct? Some of the conclusion is counter-intuitive. For
example, what is the reason to EXIT when SIGWINCH is triggered?
Could anybody let me know what signals will result in EXIT? Thanks.
$ cat script.sh
#!/usr/bin/env bash
# vim: set noexpandtab tabstop=2:
mkdir -p /tmp/trapls/pid
mkdir -p /tmp/trapls/log
echo "$$" > "/tmp/trapls/pid/$1.txt"
while IFS= read -r s
do
"/tmp/trapls/log/$1.txt"
trap "echo $(echo '"$(date)"'):$s >> /tmp/trapls/log/$1.txt" "$s"done < <(trap -l | awk -v OFS=$'\t' -e '{ for(i=2;i<=NF;i+=2) { print
$i } }'; echo EXIT)
sleep 10 &
wait "$!"
$ cat main.sh
#!/usr/bin/env bash
# vim: set noexpandtab tabstop=2:
set -v
rm -rf /tmp/trapls/pid
rm -rf /tmp/trapls/log
for s in $(trap -l | awk -v OFS=$'\t' -e '{ for(i=2;i<=NF;i+=2) {
print $i } }' | grep -v SIGSTOP | grep -v SIGCONT; echo EXIT)
do
./script.sh "$s" &
done
wait
$ cat main_kill.sh
#!/usr/bin/env bash
# vim: set noexpandtab tabstop=2:
while IFS= read -r s
do
pid=$(< "/tmp/trapls/pid/$s.txt")
echo "$(date):$s"
kill -s "$s" "$pid"
done < <(trap -l | awk -v OFS=$'\t' -e '{ for(i=2;i<=NF;i+=2) { print
$i } }' | grep -v SIGSTOP | grep -v SIGCONT; echo EXIT)
$ ./main.sh
$ ./main_kill.sh # run in a terminal different from the terminal in
which .main.sh runs.
Fri Nov 16 15:29:40 CST 2018:EXIT
Fri Nov 16 15:29:40 CST 2018:SIGHUP
Fri Nov 16 15:29:40 CST 2018:SIGINT
Fri Nov 16 15:29:40 CST 2018:SIGQUIT
Fri Nov 16 15:29:40 CST 2018:SIGILL
Fri Nov 16 15:29:40 CST 2018:SIGTRAP
Fri Nov 16 15:29:40 CST 2018:SIGABRT
Fri Nov 16 15:29:40 CST 2018:SIGEMT
Fri Nov 16 15:29:40 CST 2018:SIGFPE
Fri Nov 16 15:29:40 CST 2018:SIGKILL
Fri Nov 16 15:29:40 CST 2018:SIGBUS
Fri Nov 16 15:29:40 CST 2018:SIGSEGV
Fri Nov 16 15:29:40 CST 2018:SIGSYS
Fri Nov 16 15:29:40 CST 2018:SIGPIPE
Fri Nov 16 15:29:40 CST 2018:SIGALRM
Fri Nov 16 15:29:40 CST 2018:SIGTERM
Fri Nov 16 15:29:40 CST 2018:SIGURG
Fri Nov 16 15:29:40 CST 2018:SIGTSTP
Fri Nov 16 15:29:40 CST 2018:SIGCHLD
Fri Nov 16 15:29:40 CST 2018:SIGTTIN
Fri Nov 16 15:29:40 CST 2018:SIGTTOU
Fri Nov 16 15:29:40 CST 2018:SIGIO
Fri Nov 16 15:29:41 CST 2018:SIGXCPU
Fri Nov 16 15:29:41 CST 2018:SIGXFSZ
Fri Nov 16 15:29:41 CST 2018:SIGVTALRM
Fri Nov 16 15:29:41 CST 2018:SIGPROF
Fri Nov 16 15:29:41 CST 2018:SIGWINCH
Fri Nov 16 15:29:41 CST 2018:SIGINFO
Fri Nov 16 15:29:41 CST 2018:SIGUSR1
Fri Nov 16 15:29:41 CST 2018:SIGUSR2
$ for f in /tmp/trapls/log/*.txt; do echo "==> $f <=="; cat "$f"; done
==> /tmp/trapls/log/EXIT.txt <==
Fri Nov 16 15:29:46 CST 2018:EXIT
==> /tmp/trapls/log/SIGABRT.txt <==
Fri Nov 16 15:29:40 CST 2018:SIGABRT
Fri Nov 16 15:29:40 CST 2018:EXIT
==> /tmp/trapls/log/SIGALRM.txt <==
Fri Nov 16 15:29:40 CST 2018:SIGALRM
Fri Nov 16 15:29:40 CST 2018:EXIT
==> /tmp/trapls/log/SIGBUS.txt <==
Fri Nov 16 15:29:40 CST 2018:SIGBUS
Fri Nov 16 15:29:40 CST 2018:EXIT
==> /tmp/trapls/log/SIGCHLD.txt <==
Fri Nov 16 15:29:46 CST 2018:EXIT
==> /tmp/trapls/log/SIGEMT.txt <==
Fri Nov 16 15:29:40 CST 2018:SIGEMT
Fri Nov 16 15:29:40 CST 2018:EXIT
==> /tmp/trapls/log/SIGFPE.txt <==
Fri Nov 16 15:29:40 CST 2018:SIGFPE
Fri Nov 16 15:29:40 CST 2018:EXIT
==> /tmp/trapls/log/SIGHUP.txt <==
Fri Nov 16 15:29:40 CST 2018:SIGHUP
Fri Nov 16 15:29:40 CST 2018:EXIT
==> /tmp/trapls/log/SIGILL.txt <==
Fri Nov 16 15:29:40 CST 2018:SIGILL
Fri Nov 16 15:29:40 CST 2018:EXIT
==> /tmp/trapls/log/SIGINFO.txt <==
Fri Nov 16 15:29:41 CST 2018:SIGINFO
Fri Nov 16 15:29:41 CST 2018:EXIT
==> /tmp/trapls/log/SIGINT.txt <==
Fri Nov 16 15:29:46 CST 2018:EXIT
==> /tmp/trapls/log/SIGIO.txt <==
Fri Nov 16 15:29:41 CST 2018:SIGIO
Fri Nov 16 15:29:41 CST 2018:EXIT
==> /tmp/trapls/log/SIGKILL.txt <==
==> /tmp/trapls/log/SIGPIPE.txt <==
Fri Nov 16 15:29:40 CST 2018:SIGPIPE
Fri Nov 16 15:29:40 CST 2018:EXIT
==> /tmp/trapls/log/SIGPROF.txt <==
Fri Nov 16 15:29:41 CST 2018:SIGPROF
Fri Nov 16 15:29:41 CST 2018:EXIT
==> /tmp/trapls/log/SIGQUIT.txt <==
Fri Nov 16 15:29:46 CST 2018:EXIT
==> /tmp/trapls/log/SIGSEGV.txt <==
Fri Nov 16 15:29:40 CST 2018:SIGSEGV
Fri Nov 16 15:29:40 CST 2018:EXIT
==> /tmp/trapls/log/SIGSYS.txt <==
Fri Nov 16 15:29:40 CST 2018:SIGSYS
Fri Nov 16 15:29:40 CST 2018:EXIT
==> /tmp/trapls/log/SIGTERM.txt <==
Fri Nov 16 15:29:40 CST 2018:SIGTERM
Fri Nov 16 15:29:40 CST 2018:EXIT
==> /tmp/trapls/log/SIGTRAP.txt <==
Fri Nov 16 15:29:40 CST 2018:SIGTRAP
Fri Nov 16 15:29:40 CST 2018:EXIT
==> /tmp/trapls/log/SIGTSTP.txt <==
Fri Nov 16 15:29:40 CST 2018:SIGTSTP
Fri Nov 16 15:29:40 CST 2018:EXIT
==> /tmp/trapls/log/SIGTTIN.txt <==
Fri Nov 16 15:29:40 CST 2018:SIGTTIN
Fri Nov 16 15:29:40 CST 2018:EXIT
==> /tmp/trapls/log/SIGTTOU.txt <==
Fri Nov 16 15:29:40 CST 2018:SIGTTOU
Fri Nov 16 15:29:40 CST 2018:EXIT
==> /tmp/trapls/log/SIGURG.txt <==
Fri Nov 16 15:29:40 CST 2018:SIGURG
Fri Nov 16 15:29:40 CST 2018:EXIT
==> /tmp/trapls/log/SIGUSR1.txt <==
Fri Nov 16 15:29:41 CST 2018:SIGUSR1
Fri Nov 16 15:29:41 CST 2018:EXIT
==> /tmp/trapls/log/SIGUSR2.txt <==
Fri Nov 16 15:29:41 CST 2018:SIGUSR2
Fri Nov 16 15:29:41 CST 2018:EXIT
==> /tmp/trapls/log/SIGVTALRM.txt <==
Fri Nov 16 15:29:41 CST 2018:SIGVTALRM
Fri Nov 16 15:29:41 CST 2018:EXIT
==> /tmp/trapls/log/SIGWINCH.txt <==
Fri Nov 16 15:29:41 CST 2018:SIGWINCH
Fri Nov 16 15:29:41 CST 2018:EXIT
==> /tmp/trapls/log/SIGXCPU.txt <==
Fri Nov 16 15:29:41 CST 2018:SIGXCPU
Fri Nov 16 15:29:41 CST 2018:EXIT
==> /tmp/trapls/log/SIGXFSZ.txt <==
Fri Nov 16 15:29:41 CST 2018:SIGXFSZ
Fri Nov 16 15:29:41 CST 2018:EXIT
--
Regards,
Peng
Regards,
Peng