Будет ли cron.daily ждать окончания работы, прежде чем начинать следующую?

2409
commonpike

На этой странице http://wiki.ci.uchicago.edu/I2U2/WebalizerConfiguration предлагается переименование /etc/cron.daily/logrotate, поэтому оно следует после /etc/cron.daily/webalizer - webalizer должен быть выполнен до того, как будет запущен logrotate.

Это правда ? Будет ли cron.daily ждать окончания работы, прежде чем начинать следующую?

5

2 ответа на вопрос

5
Paul

The scripts in cron.daily and the others are executed using run-parts if anacron is not installed. You can see this in /etc/crontab:

25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily ) 

run-parts will execute each executable in the directory, and wait for each to complete before running the next. Here is a test using these two scripts:

$ cat cron/1test #!/bin/bash date echo script1 sleep 10 date $ cat cron/2test #!/bin/bash date echo script2 sleep 10 date 

Output:

$ run-parts --verbose cron run-parts: executing cron/1test Monday 6 January 10:38:42 EST 2014 script1 Monday 6 January 10:38:52 EST 2014 run-parts: executing cron/2test Monday 6 January 10:38:52 EST 2014 script2 Monday 6 January 10:39:02 EST 2014 

This differs from scheduling each job in cron, which will run them parallel if they overlap.

Хорошая работа по поиску этого. После того, как я опубликовал свой ответ, у меня появилась идея, что cron выполняет их по-разному (`/ etc / crontab` и` cron.daily`). Отлично сработано. VL-80 10 лет назад 0
1
VL-80

I just created test cron job which executes every minute:

#!/bin/bash echo "123" >> /home/user/test-file sleep 100 echo "234" >> /home/user/test-file 

So I did see overlap in htop. I mean there was periods of time when I saw two processes running simultaneously. 123 was echoed at the begging of the minute and 234 was echoed at 40 seconds of next minute (because of sleep 100). In period of 40 seconds to beginning of next minute there was just one process.

That means cron fires jobs and does not wait for them to finish.

I'll try to represent it graphically:

0 minute 00 seconds 123 <----first execution 1 minute 00 seconds 123 <----second execution 1 minute 40 seconds 234 <----first execution 2 minute 00 seconds 123 <----third execution 2 minute 40 seconds 234 <----second execution 3 minute 00 seconds 123 <----fourth execution 3 minute 40 seconds 234 <----third execution 

At least this is true for jobs in the /etc/crontab with vixie-cron on fresh updated Gentoo.

As Paul discovered - stuff in cron.daily executes in the different way.

Похожие вопросы