Source: Said.com - Open System World
Linux acts as a multi-task environment, allowing users to perform multiple tasks simultaneously, such as viewing system conditions, backup data, editing files, and print files.
For time-consuming tasks, it should not be performed in the front desk task, and should be handed over to the background task. Thus the front task can continue to work properly, do not wait. Examples are as follows:
# Find / -Name Testing &
# fg
Use "&" if you want to let the tasks in the above example into the background. However, since it is executed in the background, the output of the program does not appear on the screen. How do you manage these backend tasks when users put several tasks in the background task execution? How do you know the implementation of the background task? How to terminate or temporarily stop the execution of the background task? The following will be explained one by one.
Control management
For example, as follows:
# du -a / user> User.data &
[1] 237
# Find / -name core -type f -ls> Core.Data &
[2] 238
The three tasks are put on the back on the background as above the "&" command. Use the command "jobs -l" to display the execution of the background task, as follows:
#jobs -l
[1] 237 Running du -a / user> User.data
[2] - 238 Running Find / -Name Core -Type F -LS> Core.Data
First introduce a mission-specific noun: current task. The current task is "du -a / user >.data" because the background task number is "[1]". If the first background task is successfully implemented, the second background task is still in execution, the current task will automatically become a background task of the background task number "[2]". So you can get a little, that is, the current task will change. When the user enters "FG", "BG" and "STOP", if no quotation is added, the changes are current tasks.
Termination of background tasks
The command always has an error. When this happens, the user can end the task with the built-in command "kill" of the shell. If you want to end the background task "du -a / user> User.data", you can use the following command:
# kill 237
# kill% 1
Among them, 237 is the first backend task PID number. If you want to terminate the second background task, the following methods can:
Method 1: #KILL% 2
Method 2: # kill% -
Executive pause task
The shell's built-in command "STOP" can be used to suspend the background task. Examples are as follows:
STOP% (stop the implementation of the first background task)
STOP% N (the execution of the Nth background task)
After the use of the command "STOP", you can suspend the background task you want to stop. For example, the user must use the "nroff" command with the "nroff" command because the amount is very large, so put it in the back office. The command is as follows:
#nroff -ms moonth [1-12] .acct> Year2003.acct &
[4] 240
When the command processes half of the time, the MOONTH12.ACCT file is the old need to update. At this time, use the "jobs" command to see the background task "[4]" is still executed, but you can't know which month is processed. At this point, you can enter the following command, and save the background task "[4]" first paused:
#stop% 4
Then check the end judgment of the file year2003.acct to December. If it has not been executed, the data update of the MOONTH12.ACCT file can be updated, and the command "BG" will be temporarily stopped "[4]" will continue to be executed. This not only corrects the error file, but also does not have to re-execute the handled task once. Convenient
The front desk, the background task can indeed bring convenience to our daily operations. Because we will definitely encounter multiple operations at the same time in everyday operations. If you don't use the front desk task and background task, you will take a lot of time. Proficiency in the front desk and background tasks can reach "time" half-mexion.