如果我cat
包含mysqld_safe
和mysqld
的文本文件,则grep -w
按预期工作。但是当使用PS
输出管道时它不起作用。
ps -ef | grep -w mysqld
输出两行。
/usr/bin/mysqld_safe
/usr/libexec/mysqld
我只期待mysqld
。我知道排除选项grep -v mysqld_safe
。
版本 - grep (GNU grep) 2.5.1
答案 0 :(得分:1)
如果你有pgrep
,使用pgrep -x mysqld
会比ps + grep
更好的选择
来自man pgrep
pgrep, pkill - look up or signal processes based on name and other attributes
-x, --exact
Only match processes whose names (or command line if -f is specified) exactly match the pattern.
-l, --list-name
List the process name as well as the process ID. (pgrep only.)
-c, --count
Suppress normal output; instead print a count of matching processes. When count does not match any‐
thing, e.g. returns zero, the command will return non-zero value.
-n, --newest
Select only the newest (most recently started) of the matching processes.