Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Proper way to exit command line program?

Tags:

terminal

unix

I'm using mac/linux and I know that ctrl-z stops the currently running command in terminal, but I frequently see the process is still running when i check the system monitor. What is the right way to stop a command in terminal?

Typically I run into this issue when running python or ruby apps, i'm not sure if that has something to do with it, just thought I would add that.

like image 811
Marshall Brekka Avatar asked Nov 22 '11 04:11

Marshall Brekka


People also ask

How do you exit out of terminal program?

The keybinding to quit emacs is Ctrl-X + Ctrl-C.


1 Answers

Using control-z suspends the process (see the output from stty -a which lists the key stroke under susp). That leaves it running, but in suspended animation (so it is not using any CPU resources). It can be resumed later.

If you want to stop a program permanently, then any of interrupt (often control-c) or quit (often control-\) will stop the process, the latter producing a core dump (unless you've disabled them). You might also use a HUP or TERM signal (or, if really necessary, the KILL signal, but try the other signals first) sent to the process from another terminal; or you could use control-z to suspend the process and then send the death threat from the current terminal, and then bring the (about to die) process back into the foreground (fg).

Note that all key combinations are subject to change via the stty command or equivalents; the defaults may vary from system to system.

like image 200
Jonathan Leffler Avatar answered Sep 17 '22 11:09

Jonathan Leffler