Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I put an already-running process under nohup?

Tags:

shell

nohup

I have a process that is already running for a long time and don't want to end it.

How do I put it under nohup (that is, how do I cause it to continue running even if I close the terminal?)

like image 570
flybywire Avatar asked Mar 09 '09 08:03

flybywire


People also ask

How do you nohup an already running process?

Run our command in the first tab of our terminal. While running, we open another tab of our terminal and run the command disown -a . Then, we close the first terminal. Then our process will still run in the background even after closing the terminal.

Which command is used to place an already running process in the background?

Use bg to Send Running Commands to the Background You can easily send these commands to the background by hitting the Ctrl + Z keys and then using the bg command. Ctrl + Z stops the running process, and bg takes it to the background.

How do you put a process in the background?

In order to place a foreground proces into the background, we must first put the process to sleep, and then place it in the background. Execute the command to run your process. Press CTRL+Z to put the process into sleep. Run the bg command to wake the process and run it in the backround.

How do I move a process to the background in Linux?

You could move the running process into a background and then run other commands. To do this, you would first type ^z (hold control key and press z). That suspends the process. Then type bg to put the process in the background.


2 Answers

Using the Job Control of bash to send the process into the background:

  1. Ctrl+Z to stop (pause) the program and get back to the shell.
  2. bg to run it in the background.
  3. disown -h [job-spec] where [job-spec] is the job number (like %1 for the first running job; find about your number with the jobs command) so that the job isn't killed when the terminal closes.
like image 135
Node Avatar answered Sep 22 '22 08:09

Node


Suppose for some reason Ctrl+Z is also not working, go to another terminal, find the process id (using ps) and run:

kill -SIGSTOP PID  kill -SIGCONT PID 

SIGSTOP will suspend the process and SIGCONT will resume the process, in background. So now, closing both your terminals won't stop your process.

like image 44
Pungs Avatar answered Sep 23 '22 08:09

Pungs