Check if a process is running using Bash

后端 未结 7 932
被撕碎了的回忆
被撕碎了的回忆 2020-12-19 18:53

I am trying to check if a process is running with the code below:

SERVICE=\"./yowsup/yowsup-cli\"
RESULT=`ps aux | grep $SERVICE`

if [ \"${RESULT:-null}\" =         


        
7条回答
  •  Happy的楠姐
    2020-12-19 19:18

    Use pgrep:

    if pgrep "$SERVICE" >/dev/null 2>&1 ; then
        echo "$SERVICE is running"
    fi
    

    or, more reliable:

    if pgrep -f "/path/to/$SERVICE" >/dev/null 2>&1 ; then
        echo "$SERVICE is running"
    fi
    

提交回复
热议问题