1) How to view the process:
Ps-ef or PS aux
Root 15087 0.0 0.0 0 0? S 23:31 0:00 [kworker/1:1]
Root 15219 0.0 0.0 0 0? S 23:36 0:00 [kworker/1:0]
Root 15460 0.0 0.0 0 0? S 23:41 0:00 [Kworker/1:2]
Homer 15572 23.0 5.8 791472 119788? Sl 23:45 0:03/usr/lib/firefox/firefox
Homer 15590 0.1 0.1 273796 3132? Sl 23:45 0:00/usr/lib/at-spi2-core/at-spi-bus-launcher
Homer 15620 0.0 0.0 22360 1268 pts/0 r+ 23:45 0:00 PS aux
2) kill-9
Kill-s 9 15572
Wherein,-s 9 has developed a signal to pass to the process is 9, that is, forced to terminate the process as soon as possible. 15572 is the above PS found in Firefox (Firefox) PID.
Simple, but there is a problem, the process of small PS also does not matter, the process is more, will feel pain, whether it is ps-ef or ps-aux, each time in a large string of process information to find the process to kill the PID, look at the eyes are spent.
To use the explanation:
Kill-9, this powerful and dangerous command forces the process to terminate abruptly at run time, and the process cannot clean itself up after the end. A hazard is a system resource that is not normally released, and is generally not recommended unless other methods are invalid.
When using this command, be sure to confirm with ps-ef that there are no zombie processes left. The zombie process can be eliminated only by terminating the parent process. If the zombie process is adopted by INIT, the problem is more serious. Killing the init process means shutting down the system.
If there is a zombie process in the system, and its parent process is init, and the zombie process consumes a lot of system resources, then you need to restart the machine at some point to clear the process table.
2.1) Improved 1--grep
Pass the results of the PS query through the pipeline to grep to find the process that contains the specific string. Pipe symbol "|" Used to separate two commands, the output from the left command of the pipe character is entered as the command to the right of the pipe.
For example: [Email protected]:~$ ps-aux | grep Firefox
Homer 15572 1.7 5.0 808644 103260? Sl 23:45 0:07/usr/lib/firefox/firefox
Homer 15735 0.0 0.0 13584 920 pts/0 s+ 23:52 0:00 grep--color=auto Firefox
Directly find the Firefox process PID, input: Kill-s 9 15572
2.2) Improved 2--pgrep
Pgrep p indicates that this command is a dedicated grep for process queries
For example: [Email protected]:~$ pgrep Firefox
15572
2.3) Improved 3--pidof
Pidof command, that is, PID of XX, the literal translation comes from xx pid
For example: [Email protected]:~$ pidof Firefox
15572
2.4) Improved 4--grep + awk
grep Firefox lists the Firefox process information, and awk takes the second field, the PID
For example: [Email protected]:~$ ps-ef | grep Firefox | Grep-v grep | awk ' {print $} '
15572
2.5) Improved 5--kill + Xargs
There are several ways to kill a process:
A) PS -ef | grep Firefox | Grep-v grep | awk ' {print $} ' | Xargs kill-s 9
b) Pgrep Firefox | Xargs Kill-s 9
c) pidof Firefox | Xargs Kill-s 9
Or
d) kill-s 9 'PS -ef | grep Firefox | Grep-v grep | awk ' {print $} '
e) kill-s 9 'pgrep firefox '
f) kill-s 9 'pidof firefox '
2.6) Improved 6--pkill
Pkill similar to Pgrep, Pkill represents Pgrep+kill
Example: Pkill Firefox
3) Killall
The killall command kills all processes within the same process group, allowing you to specify the name of the process to terminate, not the PID
Killall and Pkill are similar, but if the given process name is incomplete, Killall will give an error. Pkill or pgrep can terminate a process as long as a part of the process name is given.
[Email protected]:~$ killall Firefo
Firefo:no Process found
[Email protected]:~$ killall Firefox
[Email protected]:~$ killall-9 Firefox
4) Kill
The safest way to kill a process is to simply use the KILL command, without modifiers, without flags.
Example: # Kill-pid
Note: The standard KILL command, with the default signal (signal) Number of 15, usually achieves the purpose of terminating the problematic process and releasing the process's resources to the system. However, if a process starts a child process and kills only the parent process, the child process is still running and therefore consumes resources. To prevent these so-called "zombie processes," Be sure to kill all of their child processes before killing the parent process.
5) Kill-l
Example: Kill-l PID
The-l option tells the kill command to end the process in a way that appears to the user who started the process logged off. When this option is used, the kill command also attempts to kill the left child process. But this command is not always successful--you may still need to manually kill the child process before killing the parent process.
6) Kill-hup
Sometimes you just want to simply stop and restart the process.
Example: # Kill-hup PID
This command shuts down the Linux gentle execution process and then restarts immediately. This command is handy when configuring the application, which can be executed when the configuration file is modified to restart the process.
Appendix: Various signals and their uses
Signal |
Description |
Signal number on Linux x86 |
Sigabrt |
Process aborted |
6 |
Sigalrm |
Signal raised by alarm |
14 |
Sigbus |
Bus error: "Access to undefined portion of memory object" |
7 |
SIGCHLD |
Child process terminated, stopped (or continued*) |
17 |
Sigcont |
Continue if stopped |
18 |
SIGFPE |
Floating point exception: "Erroneous arithmetic operation" |
8 |
SIGHUP |
Hangup |
1 |
Sigill |
Illegal instruction |
4 |
SIGINT |
Interrupt |
2 |
SIGKILL |
Kill (Terminate immediately) |
9 |
Sigpipe |
Write to pipe with no one reading |
13 |
Sigquit |
Quit and Dump Core |
3 |
SIGSEGV |
Segmentation violation |
11 |
SIGSTOP |
Stop Executing temporarily |
19 |
SIGTERM |
Termination (Request to terminate) |
15 |
Sigtstp |
Terminal Stop Signal |
20 |
Sigttin |
Background process attempting to read from TTY ("in") |
21st |
Sigttou |
Background process attempting to write-to-TTY ("Out") |
22 |
SIGUSR1 |
User-defined 1 |
10 |
SIGUSR2 |
User-defined 2 |
12 |
Sigpoll |
Pollable Event |
29 |
Sigprof |
Profiling Timer expired |
27 |
Sigsys |
Bad Syscall |
31 |
SIGTRAP |
Trace/breakpoint Trap |
5 |
Sigurg |
Urgent data available on socket |
23 |
Sigvtalrm |
Signal raised by Timer counting virtual time: "Virtual timer expired" |
26 |
Sigxcpu |
CPU time limit exceeded |
24 |
Sigxfsz |
File size limit exceeded |
25 |
"Reprint" Linux Kill, Killall, kill-9