On Mon, Oct 12, 2026 at 10:34:15 -0600, Stan Marsh wrote:
> From: Chet Ramey
> Subject: Re: trapped SIGTERM unexpectedly makes bash exit when received
> Date: Mon, 12 Oct 2026 10:32:10 -0400
> 
> >Because terminal emulators send SIGTERM to the foreground process group
> >when you use the `close' button instead of exiting the running application.
> 
> I don't claim any special knowledge or authority, but wouldn't that
> apply more to HUP than TERM?  HUP is the usual accepted signal for any
> kind of "the connection to the user has gone away" sort of thing.
> 
> I've never heard of TERM being used in that sort of situation.

I suppose it depends on the terminal emulator.  With Debian's xterm:

hobbit:~$ cat foo
#!/bin/bash
trap 'echo TERM' TERM
trap 'echo HUP' HUP
sleep 10000 &
wait
hobbit:~$ xterm -e './foo > bar'
hobbit:~$ cat bar
HUP

(I used fvwm's "close" feature on the xterm.)

With Debian's rxvt-unicode:

hobbit:~$ >bar
hobbit:~$ rxvt -e bash -c './foo > bar'
hobbit:~$ cat bar
HUP

Someone else can try gnome-terminal, konsole, etc. and see what they do.

  • trapped SIGT... Denys Vlasenko via Bug reports for the GNU Bourne Again SHell
    • Re: tra... Chet Ramey
      • Re:... Denys Vlasenko via Bug reports for the GNU Bourne Again SHell
        • ... Chet Ramey
          • ... Denys Vlasenko via Bug reports for the GNU Bourne Again SHell
    • Re: tra... Stan Marsh
      • Re:... Greg Wooledge
        • ... Chet Ramey
        • ... FĂ©lix Hauri via Bug reports for the GNU Bourne Again SHell
          • ... Chet Ramey

Reply via email to