This Blog primarily focus on providing solutions for administering Linux Operating system in Enterprise environment. I have put my best effort to ensure the solutions provided in this are accurate, easy to follow, effective, and helpful for Linux Users & System Administrators.
Suspending and resuming a running process in Linux
In Linux, a running process or command execution can be stopped in one terminal and made it to run from other terminal. Let say you triggered a cp command for copying some huge volumes of data from one filesystem to other, from your own workstation. After initiating the command you realized that it would take more time to complete. In this situation, you got to deal with 2 issues. One is, incase you lost the connection to server, the command execution will stop, and other one is that you have to keep your workstation connected until the command execution completes.
1. Making the job to run in back-ground is a simple solution but it is not always possible to do it, when your script/command needs some set of inputs. Syntax for making a command execution to run in the back-ground is as follows: # nohup <command set> & (e.g # nohup cp -apR /somefolder /otherfolder & ).
2. Start the job on first terminal (say Terminal-A). Open another terminal (say Terminal-B) where you can run the job uninterruptedly. On Terminal-B find out the Parent Process ID (PPID) of the Job which you started on Terminal-A.
Execute the kill command with signal 19 to Suspend the process # kill -19 <PID>
Go to Terminal-A and press Ctrl+z
Then come back to Terminal-B and execute the kill command with signal 18 to Continue the process # kill -18 <PID>
Exit from Terminal-A by running ‘exit’ command, Now your job/process will continue to run on Terminal-B.
Note: Please ensure that you suspend the PPID (Parent PID) of the Job (not the PID of its child process). If you suspend the PID of child process and exit from Terminal-A, the parent process will get hang-up signal and terminate the execution, and the PID which you suspended will become defunct process.