There is a stub application written in C. Now I want to run this application periodically, say at 11.30am daily. I thought of using the cron process but I don't know how to do it. Please help.

Also I want the cron to periodically check if the application is running normally or not. If the application crashes or hangs, cron should be able to restart the application within a certain period of time.


Cron is for running scheduled tasks at scheduled intervals, not baby sitting other processes.

You could either:

  • use something different such as the init script system of your host OS, perhaps with a custom job in inittab that will respawn itself if it dies.

  • or hack something together in the form of a shell script that periodically gets fired off by cron that checks up on your daemon script using some set of pre-determined checks for whether it is running properly or not, and if not cleans up after it then re-launches.


You can just make an entry in your crontab file

$ crontab -e

end then your entry according to http://www.manpagez.com/man/5/crontab/

30 11 * * * /path/to/your/command

With the MAILTO entry you will receive an email if the command produces output on STDERR

Checking if the process hangs is more difficult: you should define what do you mean by hangs: runs more than a certain time? Produces some recognizable behavior?

You can always have a second process or script running at a later time to check if the process is still running and take appropriate action.


Cronitor (https://cronitor.io) was a tool I built exactly for this purpose. It basically boils down to being a tracking beacon that uses http requests to record the start and end of a cron job/scheduled task.

One of the benefits of using Cronitor is that you have the flexibility to script the tracking requests and you can even make calls that will report failure immediately. With this flexibility you could possibly write a wrapper for your application that will report failures and attempt to restart the script when there are failures.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.