http://kingphp.blog.163.com/blog/static/200423244201361632639594/
When you start a program with bash, you can use it after the program, and the implementation program runs in the background;
For example: Emacs &
But if you forget to enter &; but you do not want to stop the program after the restart;
You can do this:
Press CTRL + Z to pause the foreground work, such as Emacs mentioned earlier;
Then use the jobs command to see how many programs the current bash started, you can see your emacs in it, its state is stoped; And its jobid can also be seen, for example, 2
Then use the command BG 2
So you can achieve the same effect as Emacs &.
When you have some work, such as UpdateDB, find, and so on, it takes a while to get it running in the background, and you can do other things with bash.
If you need to return the task to the front desk, only FG 2 will be required. =====================================================================================
a, Shell supports action control, with the following command:
1. command& let the process run in the background
2. Jobs view Background Running process
3. FG%n Let the background run the process N to the foreground
4. BG%n let process n Go backstage;
PS: "n" for jobs look at the process number.
B. The following turns: http://blog.chinaunix.net/u/1604/showart_1079559.html
FG, BG, Jobs, &, CTRL +z are all related to system tasks, although it is not necessary to use these commands, but it is also very useful to learn
One. & is most often used
This is used at the end of a command, you can put this command in the background to perform
Two. CTRL + Z
You can put a command that is executing in the foreground to the background and pause
Three. Jobs
See how many commands are currently running in the background
Four. Fg
Move commands in the background to the foreground to continue running
If there are more than one command in the background, you can use Fg%jobnumber to call out the selected command,%jobnumber is the serial number of the command being executed by the jobs command (not PID)
Five. Bg
Turn a command that is paused in the background to continue execution
If there are more than one command in the background, you can use Bg%jobnumber to call out the selected command,%jobnumber is the serial number of the command being executed by the jobs command (not PID)
#Using shell commands to control tasks under Linux jobs The following commands can be used to manipulate process tasks:
PS Lists the processes that are running in the system;
Kill sends a signal to one or more processes (often used to kill a process);
Jobs lists the status of the tasks that are already started in the current shell environment and displays all active task status information if no JOBSID is specified; If a task is reported to terminate (that is, the status of the task is marked as terminated), the shell from the current shell Deletes the process identity of a task in a list that is known to the environment;
BG moves the process to the background (Background);
FG moves the process to the front desk (foreground);
To move a job to a background run
If you often work in x graphics, you may have the experience of running a GUI program with a terminal command, the GUI interface is out, but your terminal is still in place, and you cannot continue to execute other commands in the shell unless you turn the GUI program off.
In order for the program to execute after the terminal can continue to accept commands, you can move the process to the background run, use the following command to run the program: #假设要运行xmms
$xmms &
This opens the XMMS, the terminal prompts back again. Now XMMS in the background, but in case you run the program and forget to use "&", and do not want to rerun, you can use the Ctrl+z suspend program, and then the BG command, so that the program will continue to run in the background.
Concept: Current Tasks
If the background task number has 2, [1],[2]; If the first background task is executed successfully and the second background task is still in progress, the current task automatically becomes the background task of the background task number "[2]". So you can draw the point that the current task is going to change. When a user enters commands such as FG, BG, and stop, the current task is changed if no quotes are added.
See Jobs
Use the jobs or PS command to see the performing jobs.
The result of the jobs command execution, + is a current job, the minus table is a job after the current job, and the JOBS-L option shows that the pid,jobs status of all tasks can be running, stopped,terminated, But if the task is terminated (kill), the shell removes the task's process identity from the list known to the current shell environment, that is, the jobs command displays the background running or suspended task information in the current shell environment;
Pending of the process
Hangs of background process:
Execute with the Stop command in Solaris, view the job number (assuming num) through the jobs command, and then execute the Stop%num;
In Redhat, no stop command exists, and the process can be suspended by executing the command kill-stop PID;
When you want to rerun the currently suspended task, the status of the pending job can be changed from stopped to running by BG%num, and it is still in the background, and the command fg%num can be executed when the need changes to the foreground.
Hangs of the foreground process:
Ctrl+z;
Termination of the process
End of background process:
Method One:
View the job number (assuming num) through the jobs command, and then execute the kill%num
Method Two:
View the job's process number (PID, assumed PID) through the PS command, and then execute kill PID
Termination of foreground process:
CTRL + C
Other effects of Kill
In addition to terminating the process, the kill can send other signals to the process, using kill-l to see the signal that the kill supports.
Sigterm is a signal that a kill sends without parameters, meaning that the process terminates, but execution depends on whether the process is supported or not. If the process is not terminated, you can use the Kill-sigkill PID, which is the kernel that terminates the process and the process cannot listen to the signal.