2017-09-29 23 views
0

我正在使用grep命令來獲取特定的進程ID,但有時我得到兩個進程ID和我的輸出是不正確的。爲進程ID grep得到正確的值

ps -ef |grep AS_Cluster.js 
root  2711 2624 0 07:15 pts/0 00:00:00 grep AS_Cluster.js 
root  14630 14625 0 Sep13 ?  00:32:36 node xx/x/xx/x/xx/AS_Cluster.js 

我想獲得這個進程ID的節點xx/xxx/xx/AS_Cluster.js的pid值。在這個

回答

0

嘗試以下

ps -ef | grep AS_Cluster.js | grep -v grep 
+1

'pgrep'較短和上述命令,使其比PID更 –

1

使用最好pgrep(1)(可能是因爲pgrep -f AS_cluster.js)或管道的ps輸出一些awk命令任何幫助 (見gawk(1))或腳本。