Hacker News new | ask | show | jobs
by layer8 649 days ago
> Another common extension is to use what is sometimes called a double Ctrl-C pattern. The first time the user hits Ctrl-C, you attempt to shut down the database cleanly, but the second time you encounter it, you give up and exit immediately.

This is a terrible behavior, because users tend to hit Ctrl-C multiple times without intending anything different than on a single hit (not to mention bouncing key mechanics and short key repeat delays). Unclean exits should be reserved for SIGQUIT (Ctrl-\) and SIGKILL (by definition).

7 comments

If you don't know about it, sure, but I find it's kind of convenient to get a safe shutdown and then be able to easily say "I don't care, just stop this program" without needing a separate kill -9 command or something.
Kids these day. Try resetting server windows on a sgi.

Subject: -42- How can I restart the X server? Date: 10 Sep 1995 00:00:01 EST

  To restart the X server (Xsgi) once, do any one of the following
  (in increasing order of brutality):

  - killall -TERM Xsgi
  - hold down the left-Control, left-Shift, F12 and keypad slash keys
    (this is fondly known as the "Vulcan Death Grip")
  - /usr/gfx/stopgfx; /usr/gfx/startgfx
  - reboot

  To restart the X server every time someone logs out of the console,
  edit /var/X11/xdm/xdm-config, change the setting of
  "DisplayManager._0.terminateServer" from "False" to "True" and do
  'killall -HUP xdm'.
As I wrote, Ctrl-\ should do the trick. And it’s just not practical having to know which program applies the double pattern, and having to train yourself to not accidentally hit Ctrl-C twice.
My brush with the double-ctrl-C pattern was in a place that wrote a lot of Java. It was generally frowned on to write any code that relied on signals which windows users can't send, and if I recall, Java made it quite difficult anyhow.

Windows does have a tradition of using ctrl-c to quit though, so SIGINT ends up being one of the few that you can use in both places. It's not pretty, but giving it a different meaning based on how many times you've ordered it seems like a somewhat natural next step, if a hacky one.

In the Meson build system's test harness, a single Ctrl-C terminates the longest running test with a SIGTERM; while three Ctrl-C in a second interrupt the whole run as if you sent the harness a SIGTERM. This was done because it's not uncommon that there are hundreds of tests left to run and you have seen what you want, and it's useful to have an intuitive shortcut for that case.

However, in both cases it's a clean shutdown, all running are terminated and the test report is printed.

> Unclean exits should be reserved for SIGQUIT (Ctrl-\) and SIGKILL (by definition).

I don't know how it works on your keyboard but on french layout, Ctrl-\ is a two-hands, three-fingers, very unpleasant on the wrist, keyboard shortcut. Not a chance I'd use that for such a common operation.

The byte that sends SIGQUIT is very much configurable with stty quit ^X , but unfortunately X has to be a-z or one of \]^_ (that is, 0x41 through 0x5F except 0x5B = [ which would conflict with other uses of ESC = ^[ = 0x1B) because of how the Ctrl modifier traditionally works. Looking at a map of AZERTY, I don’t see any good options, but you may still want to experiment.
Curiously, on many terminal emulators the following work:

Ctrl-2 = Ctrl-@ = NUL byte

Ctrl-3 = Ctrl-[ = ESC

Ctrl-4 = Ctrl-\ = default for SIGQUIT

Ctrl-5 = Ctrl-] = jump to definition in vim

Ctrl-6 = Ctrl-^ = mosh escape key

Ctrl-7 = Ctrl-_ = undo in Emacs

I think these probably originate in xterm.

I map SIGQUIT to ^Q because that's the easiest to remember.
I suppose you never hit CTRL+S by accident?
stty -ixon

Make sure that thing is disabled

I like that Konlose defaults into disabling that thing. And also that there is a visual sign of the terminal being stopped.
Ctrl-S / Ctrl-Q was super useful in the dialup modem days.
Rarely enough that needing to open another terminal and use kill to send a signal doesn't bother me.
I think the point is that it is not to be a common operation.
well I don't know, it feels like I must mash ctrl-c twenty times per day on average at least
While on UK keyboards it's the opposite "problem" - the left Ctrl key and the \ key are right next to each other (making it potentially a one-finger operation), which is the opposite of how a US keyboard is laid out (where Ctrl-\ was presumably intended to need to be a two-handed, two-finger operation).
> which is the opposite of how a US keyboard is laid out (where Ctrl-\ was presumably intended to need to be a two-handed, two-finger operation).

We have a right Ctrl, so one-hand two-finger.

When using a keyboard "properly" how are you gonna manage that?
two handed operations shouldn't exist.
I completely agree - they're very inaccessible. That's why I quoted the word "problem"; it's not actually a problem at all.
stty quit ^] ?
It's worse, because there are languages that encode interruption into the error handling functionality, so it's common that people mismanage their errors and programs require several Ctrl-C presses to actually reach the interruption handler.

What means that you have to memorize a list of "oh, this program needs Ctrl-C 3 times; oh, this program must only receive Ctrl-C once!"... I don't know of any "oh, this program needs Ctrl-C exactly 2 times", but it's an annoying possibility.

Any software I've come across that uses intentional double ctrl-c shows a message after the first ctrl-c. Something to the effect of "shutting down gracefully, press ctrl-c again for immediate shutdown".

Hence you can just press it once and wait half a second, if no message to this effect appears you can spam ctrl-c.

Yep, this is generally the pattern.
That shouldn't matter. Your database should be consistent in the face of an unclean exit. ACID has been around for a long time.
They can print a message that states that it is attempting to quit cleanly but can be forced to quit by pressing Ctrl+C another time(s). Unison does this.
While I agree in spirit, I also want to meet users where they are.