快速业务通道

linux精确定时服务

作者 佚名技术 来源 Linux系统 浏览 发布时间 2012-04-18
pEntry = head;
while (head)
{
pEntry = head->next;
free(head);
head = pEntry;
} head = NULL;
tail = NULL;
} void display_entry()
{
#if 1
ENTRY *pe;

int i;
bool n; pe = head; while (pe)
{
printf("minute: ");
for (i = 0; i <= LAST_MINUTE; i )
{
n = bit_test(pe->minute, i);
printf("%d:%d ", i, n);
}
printf("\n");

printf("hour: ");
for (i = 0; i <= LAST_HOUR; i )
{
n = bit_test(pe->hour, i);
printf("%d:%d ", i, n);
}
printf("\n");

printf("day of mon: ");
for (i = 0; i < LAST_DAYOFMON; i )
{
n = bit_test(pe->day_of_mon, i);
printf("%d:%d ", i, n);
}
printf("\n");

printf("mon of year: ");
for (i = 0; i < LAST_MONTH; i )
{
n = bit_test(pe->mon_of_year, i);
printf("%d:%d ", i, n);
}
printf("\n");

printf("day of week: ");
for (i = 0; i <= LAST_DAYOFWEEK; i )
{
n = bit_test(pe->day_of_week, i);
printf("%d:%d ", i, n);
}
printf("\n"); printf("\n"); pe = pe->next;
}

#endif
} void do_job(time_t current_time)
{
struct tm *p_tm;
ENTRY *pe;
int minute;
int hour;
int day_of_month;
int month_of_year;
int day_of_week;

p_tm = localtime(&current_time);
pe = head; minute = p_tm->tm_min - FIRST_MINUTE;
hour = p_tm->tm_hour - FIRST_HOUR;
day_of_month = p_tm->tm_mday - FIRST_DAYOFMON;
month_of_year = p_tm->tm_mon 1 - FIRST_MONTH;
day_of_week = p_tm->tm_wday - FIRST_DAYOFWEEK; #if 1
printf("%d, %d, %d, %d, %d\n",
minute,
hour,
day_of_month,
month_of_year,
day_of_week);
#endif while (pe)
{
if (bit_test(pe->minute, minute) &&
bit_test(pe->hour, hour) &&
bit_test(pe->day_of_mon, day_of_month) &&
bit_test(pe->mon_of_year, month_of_year) &&
bit_test(pe->day_of_week, day_of_week))
{
printf("%s\n", pe->command);
}

pe = pe->next;
}
} void cron_sleep(int target)
{
int seconds_to_wait; seconds_to_wait = (int)(target - time((time_t *)NULL)) 1;

if (seconds_to_wait > 0 && seconds_to_wait < 65)
sleep((unsigned int) seconds_to_wait);
} int main(int argc, char *argv[])
{
ENTRY *pEntry;
DATE_REC date;
int running_time; date.minute.flag = E_EVERY;
date.minute.low = FIRST_MINUTE;
date.minute.high = LAST_MINUTE;
date.minute.step = 2; date.hour.flag = E_NORMAL;
date.hour.low = 9;
date.hour.high = LAST_HOUR;
date.hour.step = 1; date.day_of_mon.flag = E_EVERY;
date.day_of_mon.low = FIRST_DAYOFMON;
da

凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

分享到: 更多

Copyright ©1999-2011 厦门凌众科技有限公司 厦门优通互联科技开发有限公司 All rights reserved

地址(ADD):厦门软件园二期望海路63号701E(东南融通旁) 邮编(ZIP):361008

电话:0592-5908028 传真:0592-5908039 咨询信箱:web@lingzhong.cn 咨询OICQ:173723134

《中华人民共和国增值电信业务经营许可证》闽B2-20100024  ICP备案:闽ICP备05037997号