3 回答

TA貢獻1884條經驗 獲得超4個贊
通常的技術是這樣的:
ps aux | egrep '[t]erminal'
這將匹配包含的行terminal,但egrep '[t]erminal'不匹配!它也可以在許多 Unix版本上使用。

TA貢獻1780條經驗 獲得超1個贊
它還建立在另一個答案結合使用的ps與pgrep。以下是一些相關的培訓示例:
$ 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有grep。不會打印出有用的標題行:
$? ps aux | grep [s]shd
root? ? ? 1902? 0.0? 0.1? 82560? 3580 ?? ? ? ? Ss? ?Oct20? ?0:00 /usr/sbin/sshd -D

TA貢獻1854條經驗 獲得超8個贊
另一種選擇:
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.
- 3 回答
- 0 關注
- 740 瀏覽
添加回答
舉報