Linux/Unix command to determine if process is running?

后端 未结 14 1005
忘掉有多难
忘掉有多难 2020-11-28 01:54

I need a platform independent (Linux/Unix|OSX) shell/bash command that will determine if a specific process is running. e.g. mysqld, httpd... What

14条回答
  •  广开言路
    2020-11-28 02:32

    None of the answers worked for me, so heres mine:

    process="$(pidof YOURPROCESSHERE|tr -d '\n')"
    if [[ -z "${process// }" ]]; then
      echo "Process is not running."
    else
      echo "Process is running."
    fi
    

    Explanation:

    |tr -d '\n'
    

    This removes the carriage return created by the terminal. The rest can be explained by this post.

提交回复
热议问题