Back

找出 某些command 的PID (using awk find all the pids )

发布时间: 2014-01-21 10:19:00

今天,沛沛交给我一招: awk. 找出所有的pid 列表。 ps -ef|grep fetcher |awk '{print $2}'  

例如:

$ ps -ef | grep fetcher
root     22980 22967  5 17:41 ?        00:01:45 /root/.rbenv/versions/1.9.3-p327/bin/ruby /root/.rbenv/versions/1.9.3-p327/bin/god stop fetcher
root     23041     1  0 17:41 ?        00:00:00 sh -c god stop fetcher && god start fetcher
root     23046 23041  0 17:41 ?        00:00:15 /root/.rbenv/versions/1.9.3-p327/bin/ruby /root/.rbenv/versions/1.9.3-p327/bin/god stop fetcher
root     23070     1  0 17:41 ?        00:00:00 sh -c god stop fetcher && god start fetcher
root     23072 23070  0 17:41 ?        00:00:16 /root/.rbenv/versions/1.9.3-p327/bin/ruby /root/.rbenv/versions/1.9.3-p327/bin/god stop fetcher
root     23143     1  0 17:41 ?        00:00:00 sh -c god stop fetcher && god start fetcher
root     23152 23143  0 17:41 ?        00:00:15 /root/.rbenv/versions/1.9.3-p327/bin/ruby /root/.rbenv/versions/1.9.3-p327/bin/god stop fetcher
root     23173     1  0 17:41 ?        00:00:00 sh -c god stop fetcher && god start fetcher
root     23190 23173  0 17:41 ?        00:00:16 /root/.rbenv/versions/1.9.3-p327/bin/ruby /root/.rbenv/versions/1.9.3-p327/bin/god stop fetcher
root     23245     1  0 17:41 ?        00:00:00 sh -c god stop fetcher && god start fetcher
root     23256 23245  0 17:41 ?        00:00:16 /root/.rbenv/versions/1.9.3-p327/bin/ruby /root/.rbenv/versions/1.9.3-p327/bin/god stop fetcher

使用了awk后:

$ ps -ef|grep fetcher |awk '{print $2}'  
23941
23942
23946
23951
23969
24000
24005
24009
24011
24023
24028
24043
24046
24089
24104
24121

Back