How To Suspend A Process And Resume It Later In Linux

Suspend A Process And Resume It Later In Linux

Let us you say ran a program. You didn’t know it took so long to finish. It keep running several minutes. You don’t want to wait that much long. Because, you have some other important programs to run on the queue. Have you ever been in a situation like this? No worries! I just found a simple trick to suspend a process and resume it later. What I am going to do is pause the currently running process, do some other important tasks, and then resume the stopped processes once I completed all processes.

This can be very useful when you have less RAM or Processor to do multi-task. You can pause the running processes at any time, and resume them later when you’re ready, without having to start them all over again. Sounds good? Indeed! This brief tutorial describes how to suspend or pause a running process and resume it later in Unix-like operating systems.

Suspend A Process And Resume It Later In Linux

This is absolutely an easy trick. All you have to do is find the PID (Process ID) and using ps or ps aux command, and then pause it, finally resume it when you are ready using kill command.

Let us see an example. I am going to download Ubuntu 17.04 netboot image using wget command like below.

 wget http://archive.ubuntu.com/ubuntu/dists/zesty/main/installer-amd64/current/images/netboot/mini.iso &

Here, & symbol will move the running task to the background without closing it.

Now, I want to pause this task and run other important tasks. To do so, first find the running processes i using command:

ps

Sample output:

 PID TTY TIME CMD
 8155 pts/0 00:00:00 bash
16143 pts/0 00:00:01 wget
16398 pts/0 00:00:00 ps

As you see, the PID of wget command is 16143. We are going to stop it now. To stop this process, run the following command from your Terminal:

kill -STOP 16143

Now, run the ps command to verify whether the process has been stopped or not.

ps

Sample output:

PID TTY TIME CMD
 8155 pts/0 00:00:00 bash
16143 pts/0 00:00:01 wget
16398 pts/0 00:00:00 ps

[1]+ Stopped wget http://archive.ubuntu.com/ubuntu/dists/zesty/main/installer-amd64/current/images/netboot/mini.is

Look, the process has been stopped. Now, do other important tasks. Once you completed all tasks, resume the stopped process using command:

kill -CONT 16143

Now, the process will continue. To verify it if the process is running, run ps command.

ps

Like I said already, this will be helpful if you can’t do multi-task in system that has low RAM or CPU speed.

Does this work after restarting my system?

You might ask, will this also work after a full system shutdown or reboot? NO. Because, the PIDs of the processes will automatically change after rebooting your system. They do not persist across reboot. In such cases, you can suspend or hibernate your entire system, and resume them when you are ready.

First, find the pid of the running process using ps command. Then, pause it using kill -STOP <PID>, and then hibernate your system. Resume your system and resume the stopped process using command kill -CONT <PID>.


Recommended read:


And, that’s all. You know now how to pause and resume a process in Unix-like operating systems. If you like our guides, please share them on your social, professional networks, so that other users can also benefit from them. More good stuffs to come. Stay tuned with OSTechNix.

Cheers!

Thanks for stopping by!

Help us to help you:

Have a Good day!!

You may also like...

  • Paul Grunwald

    you should add the following:

    : suspend the process
    bg : run the suspended process in the background
    fg : bring the background process to the forground

    • SK

      Thank you. I will cover bg and fg commands in a separate guide soon.