linux pgrep命令的使用

pgrep 是通过程序的名字来查询进程的工具,一般是用来判断程序是否正在运行。

常用参数

-l  列出程序名和进程ID
-o  进程起始的ID
-n  进程终止的ID
$ ps -ef | grep mysql
jiqing   27448 26025  0 16:24 pts/36   00:00:00 grep --color=auto mysql
root     29177     1  0 11月27 ?      00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/var --pid-file=/usr/local/mysql/var/Ubuntu.pid
mysql    29753 29177  0 11月27 ?      00:06:42 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/var --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/usr/local/mysql/var/Ubuntu.err --open-files-limit=65535 --pid-file=/usr/local/mysql/var/Ubuntu.pid --socket=/tmp/mysql.sock --port=3306
$ pgrep mysql
29177
29753
$ pgrep -l mysql
29177 mysqld_safe
29753 mysqld
$ pgrep -o mysql
29177
$ pgrep -n mysql
29753

如果想杀死某进程可以这样

sudo kill -9 `pgrep  mysql`
原文地址:https://www.cnblogs.com/jiqing9006/p/10032906.html