You might have always wondered what exactly on my Linux/Unix device anytime I do the Ctrl+Z
or Ctrl+C
magic to stop some programs. But what exactly is their function, what’s the difference between them?
Ctrl+C is used to kill a process with signal SIGINT
, by other words it is a polite kill.
Ctrl+Z is used to suspend a process by sending it the signal SIGSTP, which is like a sleep signal, that can be undone and the process can be resumed again.
However when a process is suspended, we can resume it again by fg
(resume in foreground) and bg
(resume in background), but I can’t resume a killed process, that is a difference between using Ctrl+C & Ctrl+Z.
How to view suspended process ?
When you have multiple suspended commands, to have them listed, you use the jobs
command, and output will be :
[1]- Stopped cat
[2]+ Stopped vi
How to kill a suspended process in background?
By using kill
command :
kill %n
where n is the job number (the one in square brackets from the jobs output), so I want to kill cat : kill %1
.