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.檢查程序的具體進程名
我不確定這一點。
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.檢查程序的具體進程名
我不確定這一點。
這是我將用於此目的:
test="$(ps aux | grep -sie "process-name" | grep -v "grep -sie")"
if [ -z "$test" ]; then exit 1; else echo "Process found ----- $test"; fi
此代碼是區分大小寫(例如:它會匹配「進程名」,而且「過程-NAME」)。
請檢查'pidof'和'pgrep'的手冊頁 –