当我检查进程列表并'grep‘出我感兴趣的进程时,grep
本身也包含在结果中。例如,要列出终端:
$ ps aux | grep terminal
user 2064 0.0 0.6 181452 26460 ? Sl Feb13 5:41 gnome-terminal --working-directory=..
user 2979 0.0 0.0 4192 796 pts/3 S+ 11:07 0:00 grep --color=auto terminal
通常我使用ps aux | grep something | grep -v grep
去掉最后一个条目...但它并不优雅:)
你有没有一个更优雅的方法来解决这个问题(除了将所有的命令打包到一个单独的脚本中,这也不是很糟糕)
发布于 2012-02-21 18:17:52
使用pgrep。它更可靠。
发布于 2012-02-21 18:22:51
您可以在ps命令中进行过滤,例如
ps u -C gnome-terminal
(或者使用find等在/proc中搜索)
发布于 2013-09-30 15:57:03
再来一个alternative
ps -fC terminal
这里有几个选项:
-f does full-format listing. This option can be combined
with many other UNIX-style options to add additional
columns. It also causes the command arguments to be
printed. When used with -L, the NLWP (number of
threads) and LWP (thread ID) columns will be added. See
the c option, the format keyword args, and the format
keyword comm.
-C cmdlist Select by command name.
This selects the processes whose executable name is
given in cmdlist.
https://stackoverflow.com/questions/9375711
复制相似问题