2016-11-21 55 views
-1
Read=$((ps -eaf | grep "$name" | grep -v grep | awk '{print $1}')) 
Read1=$((ps -p <$Read>)) 

if [ $Read1 -ne 0 ]; then 
exit 1 

存在這是我所得到的,到目前爲止,我想先拿到$名稱的PID,然後檢查是否有相對應的PID過程。如果沒有,則退出1.檢查程序的具體進程名

我不確定這一點。

+1

請檢查'pidof'和'pgrep'的手冊頁 –

回答

2

請不要重新發明輪子,請!

pidof <process name> 
+0

我認爲我們必須先找到該過程? – faker

+0

'man pidof',第一行:「_pidof - 查找正在運行的程序的進程ID._」 –

+0

如果名爲$ name的進程實際上不存在,該怎麼辦? – faker

0

這是我將用於此目的:

test="$(ps aux | grep -sie "process-name" | grep -v "grep -sie")" 
if [ -z "$test" ]; then exit 1; else echo "Process found ----- $test"; fi 

此代碼是區分大小寫(例如:它會匹配「進程名」,而且「過程-NAME」)。