We all know that in windowsProgramThe service is always running in the background, or the service is stopped. The program cannot be switched between the foreground and background. Linux provides FG and BG commands, allowing us to easily schedule running tasks.
Suppose you find it takes a long time to run a program on the front end, but you need to do other things, you can use ctrl-Z to suspend the program, then you can see the system prompt (the job number in square brackets ):
[1] + stopped/root/bin/rsync. Sh
Then we can schedule the program to the background for execution: (the number following BG is the job number)
# BG 1
[1] +/root/bin/rsync. Sh &
Run the jobs command to view running tasks:
# Jobs
[1] + running/root/bin/rsync. Sh &
If you want to call it back to the foreground, you can use
# FG 1
/Root/bin/rsync. Sh
In this way, you can only wait for the task to be completed on the console.
FG, BG, jobs, &, CTRL + Z are all related to system tasks. Although these commands are rarely used, they are also very practical.
I. & Most frequently used
This command is used at the end of a command and can be executed in the background.
II. CTRL + z
You can put a command that is being executed on the foreground in the background and pause it.
3. Jobs
View the number of commands currently running in the background
4. 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 to call up the selected command. % jobnumber is the serial number (not PID) of the command being executed in the background found through the jobs command)
5. BG
Pause a command in the background to continue execution.
If there are multiple commands in the background, you can use BG % jobnumber to call up the selected command. % jobnumber is the serial number (not PID) of the command being executed in the background found by the jobs command)