I'm using Mac and 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 the terminal?
Typically, I run into this issue when running Python or Ruby applications, I'm not sure if that has something to do with it, but just thought I would add that.
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.