每个人都知道如何恼人的是这样的:我该怎么做,而不是grep'ing ps的输出?
[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的。所以,OK,你可以这样做:
[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。有没有更好的选择?
'-p $(pgrep myserv)'而不是'-C myservice' – npostavs 2013-03-22 19:47:49
虽然我的想法是减少命令,但仍然是2. – Wrikken 2013-03-22 19:49:15