-1

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!

4 Answers4

4

Normally a unix shell will have the following key mappings

control-C => SIGINT (interupt)
control-Z => SIGTSTP (terminal stop / suspend)

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

Control-C will typically interrupt and terminate your program. But SIGINT can be handled and ignored or processed by the program.

Control-Z will typically suspend (stop) your program. But SIGSTSP can also be handled and ignored or processed by the program, although in practice this seems rarer than handling SIGINT.

Sending a SIGSTOP (kill -STOP from another terminal) will suspend (stop) your program and cannot be handled.

It looks like your key combinations that cause your program to be 'Stopped' are probably equivalent to Control-Z.

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.

Peter
  • 901
2

Try: control-C

dogbane
  • 4,746
1

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.

1

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).

Teddy
  • 7,218