Question

What does Unix Kernel do if cron job set for every minute is executing a file which takes time more than 1 minute.

For Example:

I have following Shell Command to execute PHP Script every minute.

* * * * * php /home/user/public_html/script.php

And My PHP script consists SQL code to select emails from database and send mails to given Emails using for loop.

Problem: How the system kernel will response if my database consists thousands of mail which takes more than 1 minute to finish the 1st execution.

No correct solution

OTHER TIPS

It will execute it again, unless you take steps yourself to prevent more than one instance running. You can test it by running a script that does:

date >> /tmp/a
sleep 90
date >> /tmp/a

You have 2 options:

  1. Reduce the cron frequency - to ensure the jobs finish
  2. Use a lock to prevent the job from being executed while it is running.

We often use option two and simply write a lock flag to the DB or to the filesystem - and then clear it once the script has completed.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top