문제

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.

올바른 솔루션이 없습니다

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top