How to end a program in an unix shell?

unix

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!

Best Answer

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.

Related Question