FG, BG, Jobs, &, CTRL + Z are all related to system tasks, although these commands are largely not needed now, but they are also useful
One. & is most often used
This is used at the end of a command, you can put this command in the background to execute
Two. CTRL + Z
You can put a command that is executing in the foreground in 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 multiple commands in the background, you can use FG%jobnumber to bring up the selected command,%jobnumber is the ordinal (not PID) of the command being executed in the background through the jobs command.
Five. Bg
A command that pauses in the background changes to continue execution
If there are multiple commands in the background, you can use BG%jobnumber to bring up the selected command,%jobnumber is the ordinal (not PID) of the command being executed in the background through the jobs command.
Using shell commands under Linux to control task jobs execution
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 tasks that are started in the current shell environment, and if JOBSID is not specified, displays all active task status information, and if a task is reported to be terminated (that is, the status of the task is marked as terminated), the shell Removes the process identity of the task from the list known to the current shell environment;
BG moves the process to the background (Background);
FG moves the process to the foreground (Foreground);
Move job to Background run
If you often work under X graphics, you might have experienced the following: Running a GUI program with a terminal command, the GUI interface coming out, but your terminal still in place, you can't continue executing other commands in the shell unless you turn the GUI program off.
To enable the terminal to continue accepting commands after the execution of the program, you can move the process to the background and run the program using the following command: #假设要运行xmms
$xmms &
When this opens the XMMS, the terminal prompts are back. Now the XMMS is running in the background, but in case you forget to use "&" When you run the program and don't want to re-execute it, you can use CTRL + Z to suspend the program and then tap the BG command, so the program continues to run in the background.
Concept: Current task
If there are 2 task numbers in the background, [1],[2]; If the first background task executes successfully and the second background task is still in progress, the current task will automatically become a background task for the background task number "[2]". So it can be concluded that the current task is subject to change. When the user enters commands such as FG, BG, and stop, the current task is changed if no quotation marks are added.
See Jobs
Use the jobs or PS command to view the jobs being executed.
The result of the jobs command execution, + represents a current job, the minus table is a job after the current job, 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, that is, the jobs command displays the task information that is running in the background or suspended in the current shell environment;
Process hangs
Hang of background process:
Execute through the Stop command in Solaris, view the job number (assuming num) through the jobs command, and then execute the Stop%num;
In Redhat, the Stop command does not exist, and the process can be suspended by executing the command kill-stop PID;
When you want to re-execute the currently suspended task, the status of the suspended job can be changed from stopped to running through BG%num, and the command FG%num can be executed when it needs to be executed in the foreground instead;
Foreground process hangs:
CTRL + Z;
Termination of the process
Termination of the background process:
Method One:
View the job number (assuming num) through the jobs command, and then execute the kill%num
Method Two:
Use the PS command to view the job's process number (PID, assuming PID), and then execute the kill PID
Termination of the foreground process:
CTRL + C
Other effects of Kill
In addition to terminating the process, kill can also send other signals to the process, using kill-l to see the signals that kill supports.
Sigterm is the signal that kill sends without parameters, meaning that the process terminates, but execution depends on whether the process supports it. If the process has not been terminated, you can use the Kill-sigkill PID, which is the kernel to terminate the process and the process cannot listen for this signal.
CTRL + C and CTRL + Z are both interrupt commands, but they do not work the same.
CTRL + C is the execution of a forced interrupt program,
and CTRL + Z is the task is interrupted, but this task does not end, he is still in the process he just maintain the suspended state, the user can use the FG/BG operation to continue the foreground or background tasks, FG command to restart the front desk interrupted task, The BG command places the interrupted task in the background. (Jobs view the process running in the background)
For example:
When you vi a file is, if you need to do other operations with the shell, but you do not want to shut down VI, because you have to
To save the launch, you can simply press Ctrl+z,shell will suspend the VI process ~, when you end the shell operation, you can use the FG command to continue vi your file.
CTRL + C forcibly interrupts the execution of the current program.
Ctrl+d indicates the end of the current input (that is, the user no longer issues instructions to the current program), then Linux will usually end the current program.
CTRL + Z indicates that the current foreground is always running in the background and hangs, if it needs to continue running in the background, need to "BG process number" to keep it running, and "FG process number" can be used to foreground the background process.
The meaning of ctrl+c,ctrl+d,ctrl+z in Linux
Linux: Ctrl-c sends SIGINT signals to all processes in the foreground process group. is often used to terminate a running program. Ctrl-z sends a SIGTSTP signal to all processes in the foreground process group, which is often used to suspend a process. Instead of sending a signal, ctrl-d represents a special binary value, which is a table
Under Linux:
Ctrl-c sends a SIGINT signal to all processes in the foreground process group. is often used to terminate a running program.
Ctrl-z sends a SIGTSTP signal to all processes in the foreground process group, which is often used to suspend a process.
Instead of sending a signal, ctrl-d represents a special binary value that represents EOF.
Ctrl-\ sends a sigquit signal to all processes in the foreground process group, terminates the foreground process, and generates a core file.
Key Function
Ctrl-c Kill Foreground process
Ctrl-z Suspend Foreground process
ctrl-d Terminate input, or exit shell
Ctrl-s Suspend Output
Ctrl-q Resume Output
Ctrl-o Discard Output
Ctrl-l Clear Screen
The meaning of ctrl+c,ctrl+d,ctrl+z in Linux