Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #11520

Re: SIGINT handling

From Stephane Chazelas <stephane.chazelas@gmail.com>
Newsgroups gnu.bash.bug
Subject Re: SIGINT handling
Date 2015-09-21 10:48 +0100
Message-ID <mailman.1517.1442828898.19560.bug-bash@gnu.org> (permalink)
References <20150918151439.GA16455@chaz.gmail.com> <20150919203628.GA27872@chaz.gmail.com>

Show all headers | View raw


2015-09-19 21:36:28 +0100, Stephane Chazelas:
> 2015-09-18 16:14:39 +0100, Stephane Chazelas:
> [...]
> > In:
> > 
> > bash -c 'sh -c "trap exit INT; sleep 10; :"; echo hi'
> > 
> > If I press Ctrl-C, I still see "hi".
> [...]
> 
> Jilles provided with the explanation at
> http://unix.stackexchange.com/a/230731
> 
> with a link to:
> http://www.cons.org/cracauer/sigint.html
[...]

Note that bash (and ksh, contrary to FreeBSD sh) is not
consistent in its handling of that "WCE" (for "wait and
cooperative exit") approach in that pressing ^C in:

bash -c '
  var=$(sh -c "trap \"\" INT; sleep 3; echo result)
  echo "$var"
'

kills bash, leaving the "sh" and "sleep" running unattended in
background.

Same for:

bash -O lastpipe -c '
  sh -c "trap \"\" INT; sleep 3; echo test" | read var; echo done'

One could also argue, that to be consistent, SIGTSTP and SIGQUIT
should be treated similarly (strangely enough
http://www.cons.org/cracauer/sigint.html doesn't mention SIGTSTP).

I'm not sure I prefer that WCE approach over WUE. Wouldn't it be
preferable that applications that intercept SIGINT/QUIT/TSTP for
anything other than clean-up before exit/suspend implement job
control themselves instead (like vi's :! should create a process
group and make that the foreground process group of the
terminal so pressing ^C in sh -c vi, :!sleep 10, only sends the
SIGINT to sleep)?

-- 
Stephane

Back to gnu.bash.bug | Previous | Next | Find similar


Thread

Re: SIGINT handling Stephane Chazelas <stephane.chazelas@gmail.com> - 2015-09-21 10:48 +0100

csiph-web