Linux/unix offers different multitasking with windows and a set of commands to switch back and forth tasks
BG FG & Ctrl+z nohup sitsid
 
 
 
 - Ctrl-z Suspending Program
[email protected]:~$./test.sh^z[1]+  Stopped                 ./Test.sh[email protected]: ~$
When the job is running, execution ctrl-z suspends the job and returns information such as the job's JobID, similar to the information returned with the jobs command
  
 
 -  BG Background Execution 
  [Email protected]:~$ jobs[ 1 ]  + Stopped./test.sh, [email protected]:  ~$ bg 1  [1]+./test.sh &  [email  Protected]:  ~$ 
  BG runs a pending job as a background job to re-execute these jobs in the current environment, and if the specified job is already running in the background, the BG command does not work and exits successfully. If the JobID parameter is not provided, the BG command uses the most recently suspended job 
   
 
 -  FG Foreground Run job 
  [Email protected]:~$ jobs[ 1 ]  + Stopped./test.sh, [email protected]:  ~$ FG 1   test.sh  [email protected]:  ~$ 
  FG uses the JobID parameter to indicate the specific job to run under the foreground. If you provide a JOBID,FG command to use a job that has been suspended in the background recently 
   
 
 - & Put the job in the background to execute
[Email protected]:~$./test.sh &[133511[email protected]:~$
When you run a job in the foreground, the terminal is occupied by the job, and you can use the & command to place the job in the background, and when the job runs in the background, it does not occupy the terminal. In fact, this is where the command is put into a job queue. Jobs running in the background will output the results to the screen, interfering with your work. If a job that runs in the background produces a lot of output, it's a good idea to redirect its output to a file using the following method:command >out.file 2>&1 &
  
 - Nohup ignoring hang-up signals
2>&1 &[133537[email protected]:~$ jobs
when you execute a job , you can perform a background job with parentheses () and do something like nuhup, so that the job still works when the current Shell is closed. Principle with Setsid and disown
[Email protected]:~$ (./test.sh &) [email protected]:~$ Ps-ef |grep Test515        410     1 0  One: the?xx:xx:xx/bin/sh./test.sh515      12483 21734 0  One: -pts/ A   xx:xx:xxgrep test
Use & | When BG runs a background command, its parent process is still the process of the current terminal shell, and once the parent process exits, the hangup signal is sent to all child processes, and the child process exits after receiving hangup. If we are going to continue running the process while exiting the shell, we need to use nohup to ignore the hangup signal, or use SETSID to set the parent process to the INIT process ( process number 1), or you can use the Disown command
 
   
   - Setsid
[Email protected]:~$ ps-ef |grep Test515      29710 21734 0  One: -pts/ A   xx:xx:xx/bin/sh./test.sh515      29713 21734 0  One: -pts/ A   xx:xx:xxgrep test[email protected]:~$ setsid./test.sh &[1]409[email protected]:~$ Ps-ef |grep Test515        410     1 0  One: the?xx:xx:xx/bin/sh./test.sh515        413 21734 0  One: thepts/ A   xx:xx:xxgrep test
For a foreground job that has already been performed, SETSID can set the parent process of the current job to 1, but for commands that are already running in the background we need to use the disown command
  
   - Disown
[Email protected]:~$./test.sh &[1]2539[email protected]:~$ Jobs-l[1]+2539Running./test.sh &[email protected]:~$ disown-h%1[email protected]:~$ Ps-ef |grep Test515        410    1 0  One: the?xx:xx:xx/bin/sh./test.sh515       2542 21734 0  One: thepts/ A   xx:xx:xxgrep test
For background jobs that have been performed, disown can set the parent process of the current job to 1
  
  
  
Linux Task Control