#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#define RECORD_DEBUG
#define PATH "/root/timer_record"
#ifdef RECORD_DEBUG
#define TIME 60
#define DEADLINE (2)
#else
#define TIME 600 /* 10 min*/
#define DEADLINE (60*24*7*2) /* 2 WEEKS*/
#endif
static void sleep(int sec, int usec)
{
struct timeval tv;
tv.tv_sec = sec;
tv.tv_usec = usec;
select(0,NULL,NULL,NULL,&tv);
return;
}
int main()
{
FILE *fd;
int num;
int ret;
fd = fopen(PATH,"a+");
if (fd == NULL) {
printf("Can't open file/n");
exit(1);
}
if (fscanf(fd, "%d",&num) == EOF) {
num = 0;
ret = fprintf(fd, "%d", num);
fclose(fd);
}
while (1) {
if (num >= DEADLINE)
goto done;
sleep(TIME,0);
fd = fopen(PATH,"w");
if (fd == NULL)
goto done;
num ++;
printf("num = %d/n",num);
ret = fprintf(fd, "%d", num);
fclose(fd);
}
done:
system("source /opt/Qtopia/qpe.env");
system("/opt/at6600/usr/bin/shutdown");
return 0;
}
code depository: 2 week shutdown
最新推荐文章于 2020-12-22 13:41:39 发布