1. 程式人生 > >根據關鍵詞獲取程序ID然後殺掉程序

根據關鍵詞獲取程序ID然後殺掉程序

例如需要殺掉監聽程序,如下:

[[email protected] ~]$ ps -ef|grep lsnr
oracle    4973     1  1 19:40 ?        00:00:00 /home/oracle/product/10.2.0/db_1/bin/tnslsnr LISTENER -inherit
oracle    4977  4868  0 19:40 pts/0    00:00:00 grep lsnr

使用下面的即可:
[[email protected] ~]$ ps -ef|grep lsnr|grep -v grep
oracle    4973     1  0 19:40 ?        00:00:00 /home/oracle/product/10.2.0/db_1/bin/tnslsnr LISTENER -inherit
[
[email protected]
~]$ ps -ef|grep lsnr|grep -v grep|cut -c 9-15 4973 [[email protected] ~]$ ps -ef|grep lsnr|grep -v grep|cut -c 9-15 |xargs kill -9

程序殺掉:
[[email protected] ~]$ ps -ef|grep lsnr
oracle    5071  4868  0 19:43 pts/0    00:00:00 grep lsnr

主要命令如下:lsnr是關鍵詞
[[email protected] ~]$ ps -ef|grep lsnr|grep -v grep|cut -c 9-15 |xargs kill -9