Bash check if a program is running or not

You can find process id for a running program with command

pidof BINARY_NAME_HERE

Example

boby@sok-01:~$ pidof gedit
22057
boby@sok-01:~$ ps aux | grep gedit
boby       22057  4.4  0.7 822760 60280 ?        Sl   14:29   0:00 /usr/bin/gedit --gapplication-service
boby       22071  0.0  0.0   8904   644 pts/0    S+   14:29   0:00 grep --color=auto gedit
boby@sok-01:~$ 

We can use pidof command in bash script to find if a program is running or not

if [ "$(pidof chrome)" ]
then
	echo "chrome already running."
fi

See bash

Need help with Linux Server or WordPress? We can help!

Leave a Reply

Your email address will not be published. Required fields are marked *