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.

目录

Getting Process Name via PID

We could get process name easily by the following command

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

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

pgrep command >/dev/null || command