Suspend and Resume Processes in Linux
Learn how to suspend a running process in the Linux command line. Also learn how to resume a stopped process.
Have you ever encountered a situation where you have to suspend an ongoing task as you have more important tasks to execute and want to resume the previous task later?
Actually, it is possible and can be done pretty easily using two termination signals: STOP
and CONT
.
And in this guide, I will walk you through step-by-step to suspend and resume the process again in Linux.
Suspending the process in Linux
You have two options to suspend the process:
- Using the
Ctrl + Z
shortcut (for a process running in the foreground) - Using the kill command with the
STOP
signal
1. Suspend a foreground process
Let me give you an example you can see. I run Firefox from the command line with this command:
firefox
The browser runs and you can see some strange output on the terminal. That's okay.
No, I suspend the Firefox process which is running in the foreground with the Ctrl+z terminal shortcut:
Ctrl+z
And here is what happens. The Firefox process is suspended and you can see it in the terminal. After a few seconds of delay, a dialogue box popups to notify that the Firefox browser is not responding anymore.
Ctrl+Z
keys stop (suspend) a foreground process whereas Ctrl+C
keys terminate it.2. Suspend a process by sending STOP signal
When the process is running in the background, you can not use the Ctrl + Z
shortcut. In that case, you'd have to use the kill command.
Let's see this with an example. I run the sleep command for a really long time. But I am running the command in the background by adding &
to it.
sleep 4949 &
You can verify the background processes using the jobs
command:
jobs
I can see the process ID in the example. There are various ways to find process ID. You can use the ps command and grep on the process name.
Once you have the process ID, you can suspend the process using the kill command in the following manner:
kill -STOP <PID>
In my case, the PID is 26589, then, I'd have to use the following command:
kill -STOP 26589
And as you can see, the process is stopped successfully.
Resuming the process again
To resume the process, you'd have to use the CONT
flag with the kill command as shown:
kill -CONT <PID>
In my case, the PID was 26589
then, the command would be:
kill -CONT 26589
And as you can see, after resuming the process, I used the jobs command, which showed the process was running as it should.
Know more about termination signals
Apart from STOP
and TERM
signals which I explained above, the kill command offers various other termination signals to kill the process with different effects.
And we made a detailed guide for how you can use the most popular ones:
I hope you will find this quick tip helpful.
A software engineer who loves to tinker with hardware till it gets crashed. While reviving my crashed system, you can find me reading literature, manga, or watering my plants.