Sometimes we need to know the process name via the specific pid, and sometimes vice verse, especially when only allowing one process running, so it is necessary to know how to.


Table of Contents

  1. Getting Process Name via PID
  2. Getting PID for the Specific Command
  3. Allowing Only One Process Runnnig

Getting Process Name via PID

We could get process name easily by the following command

1
ps -o comm= -p PID

Getting PID for the Specific Command

On the other hand, somtimes we wanna know the pid of specific process, we can do as following

1
2
3
pgrep command
#or
ps -ef|grep -v grep|awk '{print $1}'

Allowing Only One Process Runnnig

Having only one process running and start a new one if not running

1
pgrep command >/dev/null || command

水水更健康"o((>ω< ))o"