pgrep を使用します。より信頼性が高くなります。
通常のテクニックは次のとおりです:
ps aux | egrep '[t]erminal'
これは terminal
を含む行に一致します 、これ egrep '[t]erminal'
ではない! 多くのでも機能します Unix のフレーバー。
この回答は、以前の pgrep
に基づいています 答え。また、 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 [email protected]) 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