How can I put the current current linux process in the background?

I have a command that uploads files using git to a remote server from a Linux shell, and it will take many hours to complete.

How can I put this running program in the background? So that I can still work on the shell, and this process also ends?

+97
linux bash shell background
Dec 03
source share
1 answer

Pause the process by pressing CTRL + Z, then use the bg command to resume it in the background. For example:

 sleep 60 ^Z #Suspend character shown after hitting CTRL+Z [1]+ Stopped sleep 60 #Message showing stopped process info bg #Resume current job (last job stopped) 

Learn more about job management and using bg in the bash manual page:

CONTROL OF WORK
Entering a pause character (usually ^ Z, Control-Z) during the execution of a process causes the process to stop and returns control to bash. [...] The user can then manipulate the state of this job using the bg command to continue in the background, [...]. ^ Z takes effect immediately, and has an additional side effect, causing the pending output and typeahead to be discarded.

bg [jobspec ...]
Resume each paused job in the background, as if it were running with &. If jobspec is missing, the shell concept of the current job is used.

EDIT

To start a process where you can even kill a terminal, and it still continues to work

 nohup [command] [-args] > [filename] 2>&1 & 

eg

 nohup /home/edheal/myprog -arg1 -arg2 > /home/edheal/output.txt 2>&1 & 

To just ignore the output (not very smart), change the file name to /dev/null

To get an error message for another file, change &1 to the file name.

+184
Dec 03
source share



All Articles