【发布时间】:2013-03-12 18:47:44
【问题描述】:
每个人都知道这有多烦人:
[mybox:~ #] ps aux | grep myservice
root 2273 0.0 0.0 4360 760 ? Ss 18:06 0:00 /usr/sbin/myservice
root 18590 0.0 0.0 4100 788 pts/2 S+ 21:21 0:00 grep myservice
你得到你正在寻找的进程,加上 grep。所以,好吧,你可以这样做:
[mybox:~ #] ps aux | grep myservice | grep -v grep
root 2273 0.0 0.0 4360 760 ? Ss 18:06 0:00 /usr/sbin/myservice
或
[mybox:~ #] pgrep myservice
2273
但前者是 3 个完整的命令,而后者只为您获取进程 ID。有更好的选择吗?
【问题讨论】:
标签: shell grep shortcut idioms ps