How To Suspend A Process And Resume It Later In Linux
You say run a program. But, you didn’t know how long it will take to finish. The process keeps running several minutes. You don’t want to wait that much longer. Because, some other important programs are waiting 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 just pause the currently running process, do some other important tasks, and then resume the stopped processes once I completed all other 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, without having to start them all over again. Sounds good? Indeed!
This brief tutorial will teach you 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! 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 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:
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.
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 + Stopped wget http://archive.ubuntu.com/ubuntu/dists/zesty/main/installer-amd64/current/images/netboot/mini.is
See? The wget process has been stopped. Now, you can 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.
Like I said already, this will be helpful if you can’t do multi-task in system that has low RAM or CPU speed.
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>.
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.
- Auto Shutdown, Reboot, Suspend, Hibernate Your Linux System At A Specific Time
- Automatically Wake Up Your Linux System From Sleep Or Hibernation Mode
- Reptyr – Move A Running Process From One Terminal To Another Without Closing It
- How To Add Linux Commands To The Queue And Execute Them One By One
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.
Thanks for stopping by!
Help us to help you:
- Subscribe to our Email Newsletter : Sign Up Now
- Support OSTechNix : Donate Via PayPal
- Download free E-Books and Videos : OSTechNix on TradePub
- Connect with us: Facebook | Twitter | Google Plus | LinkedIn | RSS feeds
Have a Good day!!