Run and close the CentOS background and view the background task commands
Fg, bg, jobs, &, nohup, ctrl + z, ctrl + c command
I ,&
At the end of a command, you can put the command in the background for execution, as shown in figure
Watch-n 10 sh test. sh & # execute the test. sh script every 10 s in the background
2. ctrl + z
You can put a command that is being executed in the foreground to the background and be paused.
Iii. jobs
View the number of commands currently running in the background
The jobs-l option displays the PID of all tasks. jobs can be in the running, stopped, and Terminated states. However, if the task is terminated (kill), shell deletes the process ID of the task from the List known in the Current shell environment.
Iv. fg
Move the commands in the background to the foreground to continue running. If there are multiple commands in the background, you can use fg % jobnumber (command number, not process number) to call up the selected command.
5. bg
Change a command that is paused in the background to continue execution in the background. If there are multiple commands in the background, you can use bg % jobnumber to call up the selected command.
Vi. kill
Method 1: run the jobs command to view the job number (assuming num), and then run kill % num.
Method 2: run the ps command to view the job process number (PID, assumed to be pid), and then run the kill pid command.
Termination of the foreground process: Ctrl + c
VII. nohup
If the program is always executed in the background, it will be executed even if the current terminal is closed (previously & could not be done). nohup is required at this time. This command can continue running the corresponding process after you exit the account/Close the terminal. After the interruption is disabled, you can no longer see the program running in the background on the other terminal jobs. In this case, you can use ps (process view command)
Ps-aux | grep "test. sh" # a: show all programs u: Display x in user-based format: show all programs, not distinguished by terminals
Process Termination:
Termination of background processes: