66 views

check whether process is running or not

Today, I will discuss about existence of a process in the linux server through shell script. I will share the pseudo code for the same in the form of steps.
* Create a shell script which runs in infinite loop using while 1==1

* Inside this while loop, check the existence of a process on every 15th minute which can be achieved by dividing the minutes part of current timestamp by 15 using MOD function. If it returns 0 , go to next statements else come out of If statement.

* Inside the If function, check the process whether its running or not using ps -ef | grep -i "process_name" | wc -l

If it returns 0 that means process is not running else running.

* Take care of process_id returned for grep function itself which we don’t need to consider

* In case process is not running, then bring up that process using below command
nohup sh process_name.sh arg[0]... &

* This will make sure that process will start running at back end.
* Once your script is ready, then execute the same using nohup again.
nohup sh shell_process_exists.sh &
* It will run the script forever and check the process on every 15th minute.


Related posts