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:
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 + Zshortcut (for a process running in the foreground)
- Using the kill command with the
1. Suspend a foreground process
Let me give you an example you can see. I run Firefox from the command line with this command:
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:
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.
sleep 4949 &
You can verify the background processes using the
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
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.