suspend stop pause process

How to Suspend Process in Linux

Sometimes you may need to pause or suspend a process in Linux. This can be for various reasons. For example, if you have a long running process that takes up a lot of system resources, you may want to suspend such a process in order to run other processes. Also, if your long running process depends on the output of another process, you may need to pause it in order to finish running some dependencies. In this article, we will learn how to suspend process in Linux.


How to Suspend Process in Linux

If you are running a process in terminal, the simplest way to suspend or pause it is to hit Ctrl+Z key. When you enter this key combination, you will see a message that the process has been stopped, and display its process ID for future reference. Here is an example screenshot.

Next, if you want to run this process in background, enter bg command

$ bg

But what if your process is already running in background? In such cases, you need to first get the PID of this process, and issue Kill STOP command to stop the process. For example, let us say you run the following command.

$ wget https://downloads.joomla.org/cms/joomla3/3-8-5/Joomla_3-8-5-Stable-Full_Package.zip &

Now you can use pidof tool followed by the command whose PID you want.

$ pidof wget
4544

If there are multiple matching processes, you will see multiple PIDs in the output of above command.

Once you have the list of PIDs, you can use the following command to suspend pause/stop the process.

$ kill -STOP PID

For example, here is the command to stop process with PID 4544.

$ kill -STOP 4544

If you want to resume this process again, you can run the following command.

$ kill -CONT PID

Here is the command to restart the process with PID 4544.

$ kill -CONT 4544

You can check if your process is running or stopped with the following command.

In this article, we have learnt how to suspend process in Linux as well as how to resume it. Typically, kill command is used to terminate process. Not many people know that you can also use it to suspend and resume processes.

Also read:

How to Run Linux Commands Without Logging in History
How to Get Column Names in Pandas DataFrame
How to Change NGINX AutoIndex
How to Manage User Password Expiry & Aging in Linux
How to Remove Yum Repositories

Leave a Reply

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