Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to move a running process to background (UNIX)

Tags:

terminal

unix

ssh

I have a terminal connected to an external machine through ssh and have a process running in it. Is it possible move the execution to the background, so that I can close the ssh connection without the need to kill it? If so how?

like image 526
Miguel Avatar asked Sep 18 '17 15:09

Miguel


People also ask

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.

How can you put a process you run into 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. You can view a list of all background tasks by typing jobs in the terminal.

How do you send foreground process to background in Unix?

We can also send a foreground process to the background using the CTRL + Z shortcut. This shortcut will suspend the process; then, you can use the command bg to send it to the background.


1 Answers

Press control + Z, which will pause it and send it to the background. Then enter bg to continue it's running in the background.

Alternatively, if you put a & at the end of the command to run it in the background from the start.

This will just make it run in the background and once you log out it will still be killed. In order to keep it running after logout you will need to "disown" the process with disown -h, so that the shell doesn't count it among your processes needing to be killed on logout. See this post for more details.

like image 127
Jon Deaton Avatar answered Sep 19 '22 01:09

Jon Deaton