Quickly check if a process is running or not

Submit to reddit

When writting bash scripts one often needs to see if a process is running or not
I like the following code; though I’m sure many ways of doing this exists, what’s your favorite?

1
2
3
4
5
6
if [ -z "$(pgrep process)" ]
  then
     echo "process is not running"
  else
     echo "process is running"
fi