Linux pkill command: terminate the process, according to the user terminal number kicked out

When as in the management process, pkill command killall command and usage of the same, are a class of killing processes by name, the basic format of the command is as follows:

 

[Root @ localhost ~] # pkill [signal] process name

Table 1 lists common command signals and their meanings.

Table 1 pkill common command signal and its meaning
Signal number Signal name meaning
0 EXIT  Receive the information when the program exits.
1 HUP Hang up the telephone wires or terminals connected suspend signal, which can also cause some re-initialization process in the absence of termination.
2 INT Indicates the end of the process, but not mandatory, the commonly used "Ctrl + C" key combination to send out a signal that the kill -2.
3 QUIT drop out.
9 KILL Kill the process that terminates the process.
11 SEGV  Segmentation fault.
15 TERM Normal end of the process, is the default signal kill command.

【Example 1】

[root @ localhost ~] # pkill -9 httpd <- by name forced to kill the httpd process
[root @ localhost ~] # pstree -p | grep httpd <- view apache process and found no
[root @ localhost ~] # service httpd start <- restart apache process
starting httpd: httpd: Could not Reliably the Determine at The Server's Fully qualified Domain Me, a using 127.0.0.1 for ServerName
[the OK] [root @ localhost ~] # pstree -p | grep httpd <- Check again , apache process restart
        - httpd (11157) - + - httpd (11159)
        | | -httpd (11160)
        | | -httpd (11161)
        | | -httpd (11162)
        | | -httpd (11163)
        | | -httpd ( 11164)
        |                           |-httpd(11165)
        |                           |-httpd(11166)

pkill command kicked login

In addition, there is a pkill more important function, i.e. according to the number of terminals to kick a user login, in this case the pkill command basic format is as follows:

[Root @ localhost ~] # pkill [-t terminal number] process name

[-T terminal number] in accordance with the user option kicked terminal number;

Learning killall command, do not know if you noticed, kill sshd process by way killall command to kick the user, very easy to mistakenly kill the process, or will kill sshd service, will either kill your own login terminal.

So, already we carefully prepared learning materials system large data from Linux-Hadoop-spark -......, you need little friends can click on either the PID using the kill command to kill the login process, or use killall command to kill the process according to the name of the login process, are very easy to mistakenly kill the process, but does not use the pkill command, for example:

[the root @ localhost ~] # w
# w using the native command to query the user has logged
20:06:34 up 28 min, Users. 3, Average Load: 0.00, 0.00, 0.00
the USER @ the TTY the FROM the LOGIN the IDLE JCPU the PCPU the WHAT
the root ttyl - 19:47 18:52 0.01s 0.01s -bash
root PTS / 0 192.168.0.100 19:47 0.00s 0.09s 0.04sw
root PTS / 1 192.168.0.100 19:51 14:56 0.02s 0.02s -bash
# current host has logged three root user, a local terminal ttyl log in, the other two are telnet 192.168.0.100 from landing
[root @ localhost ~] # pkill -9 -t pts / 1
# from the forced killing pts / 1 virtual terminal login process
[root @ localhost ~] # w
20:09:09 up 30 min, 2 the Users, the Load Average: 0.00, 0.00,0.00
the USER lOGIN @ IDLE JCPU the FROM TTY PCPU the WHAT
root ttyl - 19:47 21 : 27 0.01s 0.01s -bash
root PTS / 0 192.168.0.100 19:47 0.00s Comments No comments posted 0.00sw
login process # virtual terminal pts / 1 has been killed

发布了60 篇原创文章 · 获赞 0 · 访问量 746

Guess you like

Origin blog.csdn.net/fafadsj666/article/details/104372953