I don't know whether this is right place to post this, if not please bear with me.

I have CRON that executes PHP page at 03:00 am.

This php page, goes through several data, that it takes an average 1 hour to complete, or sometimes even little more.


For some reason I don't want this cron (php page) to take more than 1 hour to process what it has made for.

So, How to kill if that page is still executing at 04:05 am.



You can achieve this kind of behavior with the timeout command.

Below is an example Configuration that kills the process if it runs longer than one hour:

* * * * * /bin/timeout -s 2 3600 /path/to/your/script.sh

-s 2 is the Signal to send to the process. 2 is the SIGINT Signal

10 is the time frame in which the process should have finished.

This Serverfault question seems very alike to your question, check it out: Can I limit the runtime of a cronjob

  • Thanks for the reply. So timeout is in seconds right? and -s 2 , I don't need to change this right? – WatsMyName Oct 4 '20 at 8:17
  • Yeah. You just need to change it if you want to send another signal. But this should kill your cronjob. Give feedback if it worked out for you :) – Lukas Räpple Oct 4 '20 at 8:43
  • 15 09 * * * /bin/timeout -s 2 120 php7.2 /project/cronfiles/cli.php TimeoutTask main this is my cron, but doesn't seem to be executing. Anything wrong? – WatsMyName Oct 4 '20 at 9:28
  • does this command work on the command line outside of crontab? you have timeout installed right? Try running it on the command, if possible and check if an error occurs. – Lukas Räpple Oct 4 '20 at 9:41
  • I found out the issue with timeout path, it should be /usr/bin/timeout – WatsMyName Oct 4 '20 at 10:33

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.