3 回答

TA貢獻(xiàn)1995條經(jīng)驗(yàn) 獲得超2個(gè)贊
通常的技術(shù)是這樣的:
ps aux | egrep '[t]erminal'
這將匹配包含的行terminal,但egrep '[t]erminal'不匹配!它也可以在許多 Unix版本上使用。

TA貢獻(xiàn)1712條經(jīng)驗(yàn) 獲得超3個(gè)贊
該答案基于先前的pgrep 答案。它還建立在另一個(gè)答案結(jié)合使用的ps與pgrep。以下是一些相關(guān)的培訓(xùn)示例:
$ pgrep -lf sshd
1902 sshd
$ pgrep -f sshd
1902
$ ps up $(pgrep -f sshd)
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1902 0.0 0.1 82560 3580 ? Ss Oct20 0:00 /usr/sbin/sshd -D
$ ps up $(pgrep -f sshddd)
error: list of process IDs must follow p
[stderr output truncated]
$ ps up $(pgrep -f sshddd) 2>&-
[no output]
以上可以用作功能:
$ psgrep() { ps up $(pgrep -f $@) 2>&-; }
$ psgrep sshd
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1902 0.0 0.1 82560 3580 ? Ss Oct20 0:00 /usr/sbin/sshd -D
用比較ps有g(shù)rep。不會(huì)打印出有用的標(biāo)題行:
$ ps aux | grep [s]shd
root 1902 0.0 0.1 82560 3580 ? Ss Oct20 0:00 /usr/sbin/sshd -D

TA貢獻(xiàn)1783條經(jīng)驗(yàn) 獲得超4個(gè)贊
另一種選擇:
ps -fC terminal
這里的選項(xiàng):
-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.
添加回答
舉報(bào)