Searching about how to suspend and resume a process in Linux? Let’s look at different methods!
Table of Contents
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
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
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
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
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
Finally, it is equally important that only processes that are stopped with the STOP signal are resumed with the CONT signal.
I am a passionate Linux expert with over 3+ years of experience in a wide range of distributions, including Ubuntu, CentOS, Arch Linux, Linux Mint, Debian, Fedora, and more. I love helping others learn Linux by writing clear guides that solve problems and teach new skills.