Shell Script – Restart Process if not found running

July 7, 2007

A script to Check if process is running and if not running
then start the process.

You can run this as a cron job in a 5/10 mins interval :

cat chk_if_process_running.sh

# check daemon
ps -ef | grep -v grep | grep daemon
# if not found - equals to 1, start it
if [ $? -eq 1 ]
/sbin/init.d/daemon start
echo "eq 0 - daemon found - do nothing"


Copy & paste from Unix desk (Linux blog)



  1. Great little script, it helped re-evaluate a problem I was having and fix it! Thanks

  2. thanks>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

  3. superrrrrrrrrrrrrrrrrrrrrrrrr

  4. Thanks! Just what I needed

  5. If u don’t have cron to run jobs (ex. Oleg firmware for wireless routers)try this script:

    if [ “X$1” != “X” ];then
    kill -9 $1 #kill previous instance of script

    if ! pidof daemon > /dev/null ;then
    //daemon start >> /dev/null &
    Echo “daemon already started”

    sleep 300 #time in seconds for recheck
    #record script pid for next kill and start another #instance
    $0 $pid

  6. Brilliant script, just what I was looking for, thanks much

  7. Great, thanks for your effort. Btw I nulled the echo output for cron use.

  8. Thanks a lot!!!!

  9. simple and does the job…..thanks

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: