Skip to main content

Process

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:

  1. Using the Ctrl + Z shortcut (for a process running in the foreground)
  2. Using the kill command with the STOP signal
🤚
A suspended process is denoted as stopped in the terminal. This may confuse you but the 'stopped process' can be resumed. After all, there is a difference between stop (SIGSTOP) and termination (SIGTERM).

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.

Example of suspending a process in Linux
Click to enlarge
💡
The 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
list background processes

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
terminate the process using kill command in terminal

And as you can see, the process is stopped successfully.

Resuming the process again

📋
There is no keyboard shortcut to resume a suspended process. 

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
resume the terminated process in Linux

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:

How to use SIGINT and other Termination Signals in Linux
Terminating executing process is more than just kill -9. Here are some of the prominent termination signals and their usage.

I hope you will find this quick tip helpful.