我想通过命令行获取进程的PID,即“cron”。 我试了下面的脚本。如何通过命令行提取进程的PID
ps ax|grep 'cron'
,但我得到一个表的一部分,
1427 ? Ss 0:00 /usr/sbin/cron -f
24160 pts/5 S+ 0:00 grep --color=auto cron
我如何提取这个PID?
我想通过命令行获取进程的PID,即“cron”。 我试了下面的脚本。如何通过命令行提取进程的PID
ps ax|grep 'cron'
,但我得到一个表的一部分,
1427 ? Ss 0:00 /usr/sbin/cron -f
24160 pts/5 S+ 0:00 grep --color=auto cron
我如何提取这个PID?
这样,例如:
ps -ef|grep 'cron'|grep -v grep|awk '{print $2}'
这是一个排除grep进程的快捷方式:'ps -ef | awk'/ [c] ron/{print $ 2}'' –
你可以试试这个;
ps -o pid,sess,cmd afx | egrep "(|/)cron(-f)?$"
或
pstree -pas <cronPID>
的pgrep
实用程序将返回进程ID为当前运行的进程匹配它的参数:
$ pgrep cron
228
它也可以用来“grep命令”的事情在命令行上:
$ pgrep -f uerfale
69749
69752
$ pgrep -l -f uerfale
69749 slogin uerfale
69752 slogin: /home/kk/.ssh/sockets/uerfale-9022-kk.sock [mux] m
致杀一个过程的名称,使用pkill
。它的工作方式与pgrep
相同,但会向匹配的进程发送信号,而不是输出进程ID。
使用:'pgrep cron' – sat