Several ways to run linux process background

  
 

Ctrl+z/bg/nohup/setsid/& In Linux, if you want the process to run in the background, in general, we can add & after the command, in fact, this is to put the command Into a job queue: # ./rsync.sh &# jobs

For commands that have been executed in the foreground, you can also re-execute them in the background. First, press ctrl+z to pause the running process. Then use the bg command to put the stopped job into the background: bg %1, put it back in the foreground: %1.

But the process executed from the top to the background, the parent process is still the process of the current terminal shell, and once the parent process exits, it will send a hangup signal to all child processes, and the child process will also exit after receiving the hangup. . If we want to continue running the process while exiting the shell, we need to use nohup to ignore the hangup signal, or setsid will set the parent process to the init process (process number is 1):

# nohup ./rsync.sh &# setsid ./rsync.sh & or # (./rsync.sh &) ////Execute # ps -ef

Copyright © Windows knowledge All Rights Reserved