Can anyone tell me the difference between ctrl+z and ctrl+c?
When I am in the terminal, both the combinations stop the current process, but what exactly is the difference between both?
command line
Can anyone tell me the difference between ctrl+z and ctrl+c?
When I am in the terminal, both the combinations stop the current process, but what exactly is the difference between both?
Best Answer
If we leave edge cases to one side, the difference is simple. Control+C aborts the application almost immediately while Control+Z shunts it into the background, suspended.
The shell send different signals to the underlying applications on these combinations:
Control+C (control character
intr
) sends SIGINT which will interrupt the application. Usually causing it to abort, but this is up to the application to decide.Control+Z (control character
susp
) sends SIGTSTP to a foreground application, effectively putting it in the background, suspended. This is useful if you need to break out of something like an editor to go and grab some data you needed. You can go back into the application by runningfg
(or%x
wherex
is the job number as shown injobs
).We can test this by running
nano TEST
, then pressing Control+Z and then runningps aux | grep TEST
. This will show us thenano
process is still running:Further, we can see (from that T, which is in the status column) that the process has been stopped. So it's still alive, but it's not running... It can be resumed.
Some applications will crash if they have ongoing external processes (like a web request) that might timeout while they're asleep.