Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Possible Duplicate:
what to do when ctrl-c can't kill a process?

On my laptop I press the laptop function key + break. On my desktop, my break key (next to print screen) is like this:

Pause
Break

If I press it (no Ctrl/Alt/etc) I get this (ignore the echo's, they're just there so I could work out what was what):

# sleep 10;echo "no ctrl/alt/shift/etc"

[12]+  Stopped                 sleep 10

If I press it with shift, I get this:

[root@ID6052 public_html]# sleep 10;echo "shift + pause/break"

[13]+  Stopped                 sleep 10

If I press it with Ctrl nothing happens.

If I press Pause/Break with Alt, I get this:

[root@ID6052 public_html]# sleep 10;echo "alt + pause/break"

[15]+  Stopped                 sleep 10

How do I get it to just stop the program? If I get a list of running processes, all these "[xx]+ Stopped..." commands show up (in a stopped state). On my laptop, pressing the func+break (ie, just normal break key...the func button is also used for scroll lock, print screen etc) closes the programs down completely!

share|improve this question

marked as duplicate by Sathya Mar 2 '11 at 9:39

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
Oh ok, i've tried ctrl+c, while it works for Sleep, other commands don't work with it. for example, do find .|less, and it doesn't quit (while in less). is there a way to quit those programs that allow text input (like less)? –  ineednotes Oct 30 '09 at 23:56
    
In this situation, less, like vim or emacs, takes measures to more fully capture keyboard input. You have to know how to exit these programs (q (maybe ^Cq if in ‘tail’ mode) in less; <ESC>:q<Return> in vim; ^X^C in emacs). Though these (and most other) programs will let you suspend (stop) them with ^Z then you can use the shell to kill them (Peter's answer mentions this). It is possible for programs to ‘grab’ ^Z though, too (technically emacs does, but, by default, it suspends itself when it gets ^Z). AFAIK, there is no single way to quit any tty program from the same tty. –  Chris Johnsen Oct 31 '09 at 0:41
    
Why is this question marked as a duplicate? It was asked in 2009, but it is duped to a question asked in 2011. What am I missing? –  Peter Feb 8 '13 at 4:46
add comment

4 Answers

Normally a unix shell will have the following key mappings

control-C => SIGINT control-Z => SIGSTOP

sometimes there is also control-y => delayed stop (not sure how this is done)

control-c will typically stop your program. But SIGINT can be handled and ignored by the program. Control-Z (seems equivalent to what you are already doing) cannot be ignored by the process. It will be forced to stop.

If you get processes in the stopped state, the your shell reports the job number. Looks like you might be using bash. Anyway, most shells will let you control stopped or background jobs using their job numbers.

kill -KILL %1
kill -9 %1
bg %1
fg %1

And so on to, kill, kill, put in background or put in foreground your (first) job respectively.

You can use the command

jobs

To list jobs currently associated with the shell you are in. Well, depending on which shell it is, which you don't specify.

share|improve this answer
add comment

Try: control-C

share|improve this answer
add comment

You can use Ctrl - C to end a program's execution in the terminal.

You can kill programs that have already been stopped with kill:

kill PID

where PID is the process id (the number you will see in ps output):

[john@awesome]$python
Python 2.4.3 (#1, Sep 17 2008, 16:04:01)
[GCC 4.1.2 20071124 (Red Hat 4.1.2-41)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
[1]+  Stopped                 python
[john@awesome]$ps
  PID TTY          TIME CMD
 3560 pts/1    00:00:00 bash
 3588 pts/1    00:00:00 python
 3609 pts/1    00:00:00 ps

Using kill without any switches is the same as using -TERM. It will attempt to gracefully close the program. If it still does not respond you can forcefully kill it with kill -9, although not recommended as it may leave behind files from opened buffers.

share|improve this answer
add comment

There are two main methods of interrupting a running program from the Unix terminal:

  1. Ctrl-c will send an INT (Interrupt) signal, which will by default make a program exit, but some programs override this.
  2. Ctrl-\ will send an QUIT signal, which will more often make a program stop running, but often will not exit as cleanly.

If these don't work, use the Ctrl-z key to suspend the program (or switch to another terminal), and the use the kill command to send the TERM or KILL signals (in that order) to the program. The latter will always terminate the program when it next has a chance to run (which is not always immediately, like if it is reading from a network file).

share|improve this answer
add comment