Kill Process Method in CentOS

Source: Internet
Author: User

1. Get the process PID and kill-s-9 pid to kill the process.

1. ps-ef

[root@justin conf]# ps -efUID PID PPID C STIME TTY TIME CMDroot 1 0 0 14:09 ? 00:00:02 /sbin/initroot 2 0 0 14:09 ? 00:00:00 [kthreadd]root 3 2 0 14:09 ? 00:00:00 [migration/0]root 4 2 0 14:09 ? 00:00:00 [ksoftirqd/0]root 5 2 0 14:09 ? 00:00:00 [migration/0]


2. ps-aux

[root@justin conf]# ps -auxWarning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQUSER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMANDroot 1 0.4 0.1 2872 1424 ? Ss 14:09 0:02 /sbin/initroot 2 0.0 0.0 0 0 ? S 14:09 0:00 [kthreadd]root 3 0.0 0.0 0 0 ? S 14:09 0:00 [migration/0]root 4 0.0 0.0 0 0 ? S 14:09 0:00 [ksoftirqd/0]


Note: You can use pipelines to precisely search for data.

[root@justin conf]# ps -aux|grep httpdWarning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQroot 1973 0.0 0.3 11648 3308 ? Ss 14:13 0:00 /usr/sbin/httpdapache 1976 0.0 0.2 11648 2128 ? S 14:13 0:00 /usr/sbin/httpdapache 1977 0.0 0.2 11648 2128 ? S 14:13 0:00 /usr/sbin/httpdapache 1978 0.0 0.2 11648 2128 ? S 14:13 0:00 /usr/sbin/httpdapache 1979 0.0 0.2 11648 2128 ? S 14:13 0:00 /usr/sbin/httpdapache 1980 0.0 0.2 11648 2128 ? S 14:13 0:00 /usr/sbin/httpdapache 1981 0.0 0.2 11648 2128 ? S 14:13 0:00 /usr/sbin/httpdapache 1982 0.0 0.2 11648 2128 ? S 14:13 0:00 /usr/sbin/httpdapache 1983 0.0 0.2 11648 2128 ? S 14:13 0:00 /usr/sbin/httpdroot 2007 0.0 0.0 4340 744 pts/0S+ 14:20 0:00 grephttpd


3. pgrep

Pgrep p indicates that this command is specially used for process query grep.

[root@justin conf]# pgrep httpd197319761977197819791980198119821983


4. pidof

Pid of xx, literally translated as the PID of xx, is slightly less than pgrep, pidof must give the full name of the process

[root@justin conf]# pidof httpd1983 1982 1981 1980 1979 1978 1977 1976 1973[root@justin conf]#


Ii. ps-ef | grep httpd | grep-v grep | cut-c 9-15 | xargs kill-s 9

Note:

The output of "grep httpd" is that all processes that contain the keyword "httpd.

"Grep-v grep" is a process that removes the keyword "grep" from the listed processes.

"Cut-c 9-15" refers to intercepting 9th to 15th characters of the input line, which is exactly the process id pid.

The xargs command in "xargs kill-s 9" is used to take the output result (PID) of the preceding command as the parameter of "kill-s 9" and execute this command. "Kill-s 9" will forcibly kill the specified process

3. pgrep httpd | xargs kill-s 9

The above command is too long to be used, and most will use this command

Iv. kill-s 9'Pgrep httpd'

5. killall-9 httpd

Complete program names must be followed by killall. Otherwise, a message is reported.

This article is from the "process is to achieve results" blog, please be sure to keep this source http://justinpeng.blog.51cto.com/7662323/1313927c

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.