0

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.

  • Were you using the same shell on MacOS as on Ubuntu? – JdeBP May 24 '20 at 21:31
  • No, macOS was bash version 3.2.57(1)-release (x86_64-apple-darwin17) – diciotto May 24 '20 at 21:32
  • The answer is that it is a quirk in the way that the readline library handles signals stemming from the fact that some terminal emulators (used to) send TERM instead of HUP to terminate the shell. See duplicate question and Chris' email conversation with the bash maintainer at https://lists.gnu.org/archive/html/bug-bash/2020-03/msg00006.html with regards to that. – Kusalananda May 24 '20 at 22:15
  • I suspected something of the kind, but isn't it strange that, being SIGTERM caught, the terminate action happens anyway? I checked the state of the signal after the handler installation with

    cat /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

0 Answers0