Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to send ssh job to background

I logged in to a remote server via ssh and started a php script. Appereantly, it will take 17 hours to complete, is there a way to break the connection but the keep the script executing? I didn't make any output redirection, so I am seeing all the output.

like image 894
yasar Avatar asked Nov 18 '11 15:11

yasar


People also ask

How do I set a background in SSH session?

Using nohup command to Keep Running SSH Sessions If you are not that familiar with screen or tmux, you can use nohup and send your long running command to background so that you can continue while the command will keep on executing in background. After that you can safely log out.

How do I push a process to run in the background?

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 do I move a Linux task to the background?

To move foreground jobs in the background, we use the bg command in the Linux system. bg (background) – The bg command is used to move foreground jobs in the background. It resumes execution of a suspended process in the background. If no job is specified, then the bg command work upon the currently running process.

How do I change foreground process to background in Linux?

Move a Foreground Process to Background To move a running foreground process in the background: Stop the process by typing Ctrl+Z . Move the stopped process to the background by typing bg .


2 Answers

Can you stop the process right now? If so, launch screen, start the process and detach screen using ctrl-a then ctrl-d. Use screen -r to retrieve the session later.

This should be available in most distros, failing that, a package will definitely be available for you.

like image 50
Steve Rukuts Avatar answered Oct 21 '22 09:10

Steve Rukuts


ctrl + z 

will pause it. Than type

bg

to send it to background. Write down the PID of the process for later usage ;)

EDIT: I forgot, you have to execute

disown -$PID

where $PID is the pid of your process

after that, and the process will not be killed after you close the terminal.

like image 26
hovanessyan Avatar answered Oct 21 '22 08:10

hovanessyan