FG, BG, Jobs, &, Nohup, CTRL + Z, CTRL + C command
First, &
At the end of a command, you can put this command in the background to execute, as
Watch -n-sh test.sh & #每10s在后台执行一次test. Sh script
Two, CTRL + Z
You can place a command that is being executed in the foreground in the background and be in a paused state.
Third, Jobs
See how many commands are currently running in the background
The JOBS-L option shows the Pid,jobs status of all tasks can be running, stopped, Terminated. However, if the task is terminated (kill), the shell removes the process identity of the task from the list known to the current shell environment.
Iv. FG
The commands in the background are moved to the foreground to continue running. If there are multiple commands in the background, the selected command can be paged out with FG%jobnumber (which is the command number, not the process number).
V. BG
A command that pauses in the background changes to execute in the background . If there are multiple commands in the background, you can use BG%jobnumber to bring up the selected command.
Vi. Kill
- Scenario 1: View the job number (assuming num) with the jobs command and then execute the kill%num
- Scenario 2: View the Job's process number (PID, assuming PID) with the PS command and then execute the kill PID
Termination of the foreground process: Ctrl + C
Seven,nohup
If the program is always executed in the background, even if the current terminal is closed (& cannot be done before), Nohup is required. This command can continue to run the process after you exit the account/close the terminal. After the interruption, the other terminal jobs can not see the background running program, at this time using PS (Process view command)
Ps-aux | grep "test.sh" #a: Show All Programs U: Display x in user-oriented format: Show All Programs, do not differentiate by terminal
Linux background running process FG BG CTRL + Z