Linux background process management and the difference between ctrl+z (suspend), ctrl+c (interrupt), ctrl+\ (exit) and ctrl+d (EOF)

1. Background process management commands

fg, bg, jobs, &, ctrl + z, ctrl + c, ctrl + \, ctrl + d
1, &
at the end of a command, you can put this command in the background to execute, such as gftp &,
2, ctrl + z
You can put a command that is being executed in the foreground into the background, and it is in a suspended state, which cannot be executed
. 3. Jobs to
view how many commands are currently running in the background. The
jobs -l option can display the PID of all tasks, and the status of jobs can be running, stopped, Terminated, but if the task is terminated (kill), the shell removes the task's process id from the list known to the current shell environment; that is, the jobs command shows that the background from the current shell environment is running Or the suspended task information;
4. fg
transfers 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 out the selected command. %jobnumber is found through the jobs command. The serial number of the command being executed in the background (not pid)
5. bg
will change a command suspended in the background to continue execution (execute in the background).
If there are multiple commands in the background, you can use bg %jobnumber to call out the selected command , %jobnumber is the serial number (not pid) of the command being executed in the background found by the jobs command.
Transfer the task to the background:
first ctrl + z; then bg, so that the process is moved to the background to run, and the terminal can continue to accept Order.
Concept: Current Task
If there are 2 task numbers in the background, [1], [2]; if the first background task is successfully executed and the second background task is still being executed, the current task will automatically become the background task number" [2]" background task. So it can be concluded that the current task will change. When the user enters commands such as "fg", "bg" and "stop", if no quotation marks are added, all the changes are the current task

2. Termination of the process Termination of the
background process:
Method 1:
View the job through the jobs command Number (assume num), and then execute kill %num
Method 2:
Check the process number (PID, assumed to be pid) of the job through the ps command, and then execute kill pid
to terminate the foreground process:
ctrl+c

3. Suspend the process ( Suspend the meaning of the
background process:
execute the stop command in solaris, check the job number (assuming num) through the jobs command, and then execute stop %num;
in redhat, there is no stop command, you can execute the command kill -stop PID to suspend the process;
when the currently suspended task is to be re-executed, the status of the suspended job can be changed from stopped to running through bg %num, and it is still executed in the background; when it needs to be changed to When executing in the foreground, execute the command fg %num;
the suspension of the foreground process:
ctrl+Z;

 

4. Other functions of
kill In addition to terminating the process, kill can also send other signals to the process. Use kill -l to view the signals supported by kill.
SIGTERM is a signal sent by kill without parameters, which means that the process is to be terminated, but it depends on whether the process supports it or not. If the process has not terminated, you can use kill -SIGKILL pid, which is terminated by the kernel, and the process cannot listen for this signal.

 

5. The difference between ctrl+z (suspend), ctrl+c (interrupt), ctrl+\ (exit) and ctrl+d (EOF)

 

1. The performance of the four operations

ctrl+c forcibly interrupts the execution of the current program.
ctrl+z interrupts the task, but the task is not over, he is still in the process, just put it in the background and maintain a suspended state. If you want it to continue running in the background, you need to use "bg process ID" to keep it running; then use "fg process ID" to bring the background process to the foreground.

ctrl+\ means exit.

ctrl+d means to end the current input (that is, the user no longer gives instructions to the current program), then Linux will usually end the current program.

2, ctrl+c, ctrl+d, ctrl+z meaning in linux.

Under linux:
ctrl-c sends a SIGINT signal to all processes in the foreground process group. Often used to terminate a running program.
ctrl-z sends a SIGTSTP signal to all processes in the foreground process group, often used to suspend a process.
Instead of sending a signal, ctrl-d represents a special binary value, which means EOF.
ctrl-\ Send a SIGQUIT signal to all processes in the foreground process group, terminate the foreground process and generate 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

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325024993&siteId=291194637