Here's what happens in Ubuntu (Linux ubuntu 5.3.0-53-generic #47~18.04.1-Ubuntu SMP Thu May 7 13:10:50 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux, bash 4.4.20(1)):
In Terminal, open a window (let's call it "window_1") and type:
trap "echo something;" SIGTERM
then
echo $$
9781
then
kill -TERM $$
as expected, something is printed in window_1 and the window stays open.
Now open another "window_2" and type:
kill -TERM 9781
and window_1 is closed (no time to see whether something is printed).
Do the same with SIGINT and everything works as expected.
Do the same with SIGUSR1 and everything works as expected, but only after the Enter key is pressed. Also, in macOS 10.13.6 everything works as expected (with SIGTERM, SIGINT and SIGUSR1).
Is anybody able to explain this apparent anomaly?
Thanks in advance.
TERM
instead ofHUP
to terminate the shell. See duplicate question and Chris' email conversation with thebash
maintainer at https://lists.gnu.org/archive/html/bug-bash/2020-03/msg00006.html with regards to that. – Kusalananda May 24 '20 at 22:15cat /proc/$$/status | grep SigCgt
and I got
SigCgt: 000000004b817efb
Which, being SIGTERM number 15, means SIGTERM is definitely handled.
– diciotto May 25 '20 at 07:44