Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

There are Linux programs, for example vlc, that recommend typing ctrl+c twice to kill their execution from a terminal if the program didn't stop after the first one.

Why would typing ctrl+c twice work when the first time didn't work?

share|improve this question
5  
[citation needed] –  Ignacio Vazquez-Abrams Aug 21 '11 at 8:44
add comment

2 Answers 2

up vote 33 down vote accepted

What it does is entirely application specific. When you press ctrl+c, the terminal emulator sends a SIGINT signal to the foreground application, which triggers the appropriate "signal handler". The default signal handler for SIGINT terminates the application. But any program can install its own signal handler for SIGINT (including a signal handler that does not stop the execution at all).

Apparently, vlc installs a signal handler that attempts to do some cleanup / graceful termination upon the first time it is invoked, and falls back to the default behavior of instantly terminating execution when it is invoked for a second time.

share|improve this answer
3  
On some systems, the signal gets reverted to SIG_DFL after a call to the handler (to avoid calling the handler twice on the same signal); this is called SysV semantics. Many programs do not set the signal handler back to the original on-program settings at the end of the handler. This would normally be a programming bug. Read more information on the signal(2) manpage. –  Arcege Aug 21 '11 at 18:24
add comment

SIGINT, the signal sent by Ctrl+C, conventionally tells a program to break out to its main command processing loop, or if that doesn't make sense, to exit cleanly. Some programs run a cleanup procedure when they receive a SIGINT. If the program is so messed up that the cleanup procedure fails, in some programs, a second Ctrl+C causes the program to quit immediately. Doing this is up to each program author.

If a second Ctrl+C doesn't kill the program, try Ctrl+\, which sends SIGQUIT, a more violent (but still catchable signal), or try Ctrl+Z to suspend the program and then the kill command (e.g. kill %1 which sends SIGTERM, a conventionally less violent signal than SIGQUIT, to job number 1). If all else fails, kill the program with kill -KILL, also known as kill -9, sending the uncatchable signal SIGKILL.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.