In Linux, there are times when you might want to suspend a running process temporarily. This can come in handy in a number of circumstances, such as when you need to free up system resources or wish to halt a time-consuming job to continue it later. In this article, we will look at how to suspend a process in Linux so if you are interested read this guide.
How to suspend a process in Linux
To suspend a process in Linux, you can use the kill command with the SIGSTOP signal. This signal instructs the operating system to stop the process temporarily, allowing you to resume it later, here are the steps to suspend a process in Linux:
Step 1: Find the process ID
The first step is to find the process ID (PID) of the process you want to suspend, and you can do this by running the ps command, which lists all running processes. To make it easier to find the process you want, you can use the grep command to filter the results based on the process name and here is the syntax for it:
ps -ef | grep <process-name>
This command will list all processes that contain the string <process-name> and for illustration I have replaced the string with testscript which is currently running:
Step 2: Suspend the process
After you have got the ID of the process which you want to suspend, use the kill command to send the SIGSTOP signal to the process, the syntax of the command is as follows:
kill -SIGSTOP <PID>
For example, in my case the PID of the process which I want to suspend is 2840, so I have used the above syntax like this:
kill -SIGSTOP 2840
This will send the SIGSTOP signal to the process, causing it to stop temporarily:
Step 3: Resume the process
To resume the process, you can use the kill command again, this time sending the SIGCONT signal. This signal instructs the operating system to resume the process where it left off, the syntax of the command is as follows:
kill -SIGCONT <PID>
For example, to resume the similar process we suspended can be recontinued using its PID that was 2840 using the above given syntax:
kill -SIGCONT 2840
This will resume the process from where it left off:
Suspending a process in Linux can be a useful tool for managing system resources and pausing long-running tasks. By using the kill command with the SIGSTOP and SIGCONT signals, you can easily suspend, and resume processes as needed.
In case if you are interested in killing the process, use this guide.