Linux Commands

How to Suspend a Process in Linux

Process suspension or suspend a job refers to a process that has been turned off from the running state. Although the process exists, it is not scheduled for execution. Consider a server on which you wish to run CPU-intensive experimental and computational programs that will take two months to complete.

Why Do We Need to Suspend a Process?

You can suspend a process for a variety of reasons. The most important of which is when a large number of interactive requests come in for processing. The memory management system swaps the process out of memory to make space for other processes.

We will demonstrate in this article how to kill or suspend a process in a Linux system.

Suspend a Process in Linux

It is quite an easy job to suspend a process in Linux. In UNIX, by typing ‘Ctrl+Z’, you can suspend the job that is currently connected to your terminal. The command prompt will notify you that the process has been stopped. It will assign a process ID to the suspended job.

If you want to run this process in the background, then type the ‘bg’ command:

When there is no other option available to suspend a process, we can stop it manually by using the terminal.

To suspend or terminate a process, first, you will find the PID (process ID) using the ‘pd’ command. Once you found the process id, you can suspend this job by using the kill, pkill, killall, or top commands.

Example

For example, we want to download a Joomla full stable package via the wget command using the terminal.

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

It takes much time to complete as compared to other processes. To check the process id, use the following command:

$ ps

You can also find the process id for a specific running job using this command:

$ pidof wget

If multiple files are downloading in the background of your system, use this command:

$ ps aux | grepwget

Once you found the process id, you can suspend the job using the process id using the following ‘kill’ command:

$ kill -STOP PID

For example, we want to kill or suspend a job having process id ‘5562’. In this case, use this command:

$ kill -STOP 5562

If you want to run this process again, use this command:

$ kill -CONT 5562

View the running process id by using the following command:

$ ps

Conclusion

We discussed in this post how to suspend a process in Linux using two methods: the keyboard shortcut and through the terminal. However, if you restart your system, this technique will not work. When you reboot your system, the process ids of all processes will automatically change.

About the author

Karim Buzdar

Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. He blogs at LinuxWays.