How to Suspend and Resume a Process in Linux: 2 Easy Methods

Searching about how to suspend and resume a process in Linux? Let’s look at different methods!

How to Suspend a Process in Linux?

In Linux, you can commonly suspend and resume processes by using signals. This task is a routine part of managing system resources.

Moreover, it allows high control over the operating system’s processes.

To suspend a process, use two primary methods:

1. Using the Ctrl+Z Shortcut

This shortcut method works for processes running in the foreground. To utilize this, simply press Ctrl+Z in the terminal interface. It then suspends the process, denoted as stopped in the terminal.

For instance, currently, Firefox is running from the command line and we need to suspend it.

Let’s hit Ctrl+Z to suspend the firefox:

firefox
suspend a process using ctrl z in linux

2. Using the kill Command with the STOP Signal

Alternatively, you can also use the kill command with the -STOP signal with the Process ID (PID) for background processes. It stops the process without terminating it.

For example, find the PID 9931 of bash using the ps command. After that, suspend the process via the kill command with -STOP option:

ps
kill -STOP 9931
kill a process using p_id in linux

How to Resume a Process in Linux?

In certain situations, you may need to resume a suspended process. It is possible to use the fg command with process ID or signals like, STOP and CONT with the kill command.

1. Using the fg Command With Process ID

The fg command resumes the processes running in the foreground.

Let’s first find the job ID with the jobs command and then use fg %job_id to bring it back to the foreground:

jobs
fg %2
resume a process with job_id in linux

Additionally, the bg command is also utilized to continue the process in the background after suspension for background processes.

Let’s resume the sleep 500 process:

jobs
bg $1
resume a process using j_id in linux

2. Using the kill Command with the CONT Signal

To resume the process, use kill -CONT <PID>. It sends the CONT signal to the process, which permits it to continue where it is knocked out or left off.

Let’s replace the <PID> with the actual process ID 9931 of the suspended task:

kill -CONT 9931
ps
resume a process using p_id in linux

Finally, it is equally important that only processes that are stopped with the STOP signal are resumed with the CONT signal.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top