
Proper handling of SIGINT/SIGQUIT (2013) - teddyh
http://www.cons.org/cracauer/sigint.html
======
teddyh
Abstract:

 _In UNIX terminal sessions, you usually have a key like C-c (Control-C) to
immediately end whatever program you have running in the foreground. This
should work even when the program you called has called other programs in
turn. Everything should be aborted, giving you your command prompt back, no
matter how deep the call stack is._

 _Basically, it’s trivial. But the existence of interactive applications that
use SIGINT and /or SIGQUIT for other purposes than a complete immediate abort
make matters complicated, and – as was to expect – left us with several ways
to solve the problems. Of course, existing shells and applications follow
different ways._

 _This web page outlines different ways to solve the problem and argues that
only one of them can do everything right, although it means that we have to
fix some existing software._

------
ambrop7
I'm curious, isn't there a race condition in the WCE method, where:

(1) The child terminates normally, never having received SIGINT.

(2) The parent receives SIGINT before it reaches the wait() call, or while in
the wait() call but before the child termination is picked up (I suppose in
the later case wait() might fail and be restarted).

(3) Once the parent sees that the child terminated normally, it does not exit,
and SIGINT was effectively ignored.

~~~
davekeck
I don't see a race -- the article says: "Take no action when SIGINT is
received while you wait for a child. You make a note of the fact that you did
receive it, though."

Then, after waiting on the child, "Look at whether you (the shell) has
received SIGINT while the child was in the foreground", and the shell kills
itself with SIGINT if so.

------
makecheck
Many times I've had to Control-Z a process (suspend it) and then kill it,
because Control-C did not propagate correctly. And even then, the kill usually
required a "kill -9".

It would be great if consistent interruption could be solved once and for all.
In many cases, the presence of sub-processes is essentially an "implementation
detail" of the program you're trying to interrupt but you just don't know if
the Control-C will work or if the shell will just sit there and hang. And many
people are not aware of what shells can do either so they try even more
extreme things like closing entire terminal windows to cope.

------
Freaky
The cvsweb links are semi-broken. Relevant SVN commit:
[http://v4.freshbsd.org/commit/freebsd/src/38520](http://v4.freshbsd.org/commit/freebsd/src/38520)

------
762236
I had to look it up, since it is so rarely used: Sigquit is often mapped to
ctrl-\

~~~
teddyh
Also, “Ctrl-\” (and hence SIGQUIT) is often also available as “Ctrl-4”. This
is especially useful in case your keyboard does not have the US keyboard
layout, and has placed the ‘\’ character on a key combination which is hard to
type.

------
dang
Anybody want to come up with a year for this one?
[https://web.archive.org/web/*/http://www.cons.org/cracauer/s...](https://web.archive.org/web/*/http://www.cons.org/cracauer/sigint.html)
is daunting.

~~~
otterley
It's 2013; see the modification date at the bottom.

~~~
dang
It depends on how big the modification was. We're looking for the year the
article was written, not when it was last tweaked.

