How to keep a job running in Linux

There are many ways to keep a process running on linux but I haven’t seen any that are as easy to implement as the script below.

Basically the script does a ps ax and then a grep for your process. If it’s not running it will re-start the process.

You install the script into your crontab i.e. crontab -e

As a bonus this mechanism will re-start your process after a re-boot.

Edit your crontab

Cut and paste the following code into your crontab.

*/5 * * * * /home/path_to_the_script/

Make sure the cron entry is pointing to where your is located.

The Bash script

# make sure a process is always running. 
# Add the following to the crontab (i.e. crontab -e)
# */5 * * * * /home/path_to_make_run/


if ps ax | grep -v grep | grep $process > /dev/null 
 $makerun &

Test the script on it’s own first to make sure it starts your job.


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.