📄 dsq.c
字号:
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <stdarg.h>
#include <time.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <signal.h>
//月份的英文字符与数字的对照
char* tbMon[12][2]={
{"Jan","01"},
{"Feb","02"},
{"Mar","03"},
{"Apr","04"},
{"May","05"},
{"Jun","06"},
{"Jul","07"},
{"Aug","08"},
{"Sep","09"},
{"Oct","10"},
{"Nov","11"},
{"Dec","12"}
};
void dsq();
void intr_hdlr();
int gettime(int limonth, int liday, int lihour, int liminute, int lisecond);
int myitoa(int myi,char* mya,int length);
int myltoa(long myl,char* mya,int length);
void main(int argc,char* argv[])
{
pid_t pid;
char* prgnamep;
prgnamep=argv[0];
/*if (argc < 2) {
printf(" Usage: %s \n", prgnamep);
exit(1);
}*/
if ((pid = fork()) > 0) {
//sleep(3);
exit(0);
}
else if (pid==0) {
sigset( SIGHUP, (void (*)()) intr_hdlr );
sigset( SIGINT, (void (*)()) intr_hdlr );
sigset( SIGQUIT, (void (*)()) intr_hdlr );
sigset( SIGTERM, (void (*)()) intr_hdlr );
dsq();
exit(0);
}
else
{
printf(" Error forking child process.");
exit(1);
}
}
void dsq()
{
/*0 0 25 1 0-6 sh /u1/xt170/CV_MONTH 1
0 0 25 2 0-6 sh /u1/xt170/CV_MONTH 2
0 0 25 3 0-6 sh /u1/xt170/CV_MONTH 3
0 0 25 4 0-6 sh /u1/xt170/CV_MONTH 4
0 0 25 5 0-6 sh /u1/xt170/CV_MONTH 5
0 0 25 6 0-6 sh /u1/xt170/CV_MONTH 6
0 0 25 7 0-6 sh /u1/xt170/CV_MONTH 7
0 0 25 8 0-6 sh /u1/xt170/CV_MONTH 8
0 0 25 9 0-6 sh /u1/xt170/CV_MONTH 9
0 0 25 10 0-6 sh /u1/xt170/CV_MONTH 10
0 0 25 11 0-6 sh /u1/xt170/CV_MONTH 11
0 0 25 12 0-6 sh /u1/xt170/CV_MONTH 12
30 1,13 * * 0-6 sh /u1/xt170/cv_script/cv_hfcj
*/
char strexecmonth[80];
char strexecany[80];
int monthflag;
int anytimeflag;
int dimonth,diday,dihour,diminute,disecond;
while(1){
sleep(1);
gettime(dimonth,diday,dihour,diminute,disecond);
//每天执行多次的定时器
if(((dihour==1)&&(diminute==30))||((dihour==13)&&(diminute==30))){
if(anytimeflag==0){
sprintf(strexecany, "sh /u1/xt170/cv_script/cv_hfcj");
system(strexecany);
anytimeflag=1;
}
}
else{
anytimeflag=0;
}
//每月执行一次的定时器
switch(dimonth){
case 1:
if((diday==25)&&(dihour==0)&&(diminute==0)){
if(monthflag==0){
sprintf(strexecmonth, "sh /u1/xt170/CV_MONTH %s", "1");
system(strexecmonth);
monthflag=1;
}
}
else{
monthflag=0;
}
break;
case 2:
if((diday==25)&&(dihour==0)&&(diminute==0)){
if(monthflag==0){
sprintf(strexecmonth, "sh /u1/xt170/CV_MONTH %s", "2");
system(strexecmonth);
monthflag=1;
}
}
else{
monthflag=0;
}
break;
case 3:
if((diday==25)&&(dihour==0)&&(diminute==0)){
if(monthflag==0){
sprintf(strexecmonth, "sh /u1/xt170/CV_MONTH %s", "3");
system(strexecmonth);
monthflag=1;
}
}
else{
monthflag=0;
}
break;
case 4:
if((diday==25)&&(dihour==0)&&(diminute==0)){
if(monthflag==0){
sprintf(strexecmonth, "sh /u1/xt170/CV_MONTH %s", "4");
system(strexecmonth);
monthflag=1;
}
}
else{
monthflag=0;
}
break;
case 5:
if((diday==25)&&(dihour==0)&&(diminute==0)){
if(monthflag==0){
sprintf(strexecmonth, "sh /u1/xt170/CV_MONTH %s", "5");
system(strexecmonth);
monthflag=1;
}
}
else{
monthflag=0;
}
break;
case 6:
if((diday==25)&&(dihour==0)&&(diminute==0)){
if(monthflag==0){
sprintf(strexecmonth, "sh /u1/xt170/CV_MONTH %s", "6");
system(strexecmonth);
monthflag=1;
}
}
else{
monthflag=0;
}
break;
case 7:
if((diday==25)&&(dihour==0)&&(diminute==0)){
if(monthflag==0){
sprintf(strexecmonth, "sh /u1/xt170/CV_MONTH %s", "7");
system(strexecmonth);
monthflag=1;
}
}
else{
monthflag=0;
}
break;
case 8:
if((diday==25)&&(dihour==0)&&(diminute==0)){
if(monthflag==0){
sprintf(strexecmonth, "sh /u1/xt170/CV_MONTH %s", "8");
system(strexecmonth);
monthflag=1;
}
}
else{
monthflag=0;
}
break;
case 9:
if((diday==25)&&(dihour==0)&&(diminute==0)){
if(monthflag==0){
sprintf(strexecmonth, "sh /u1/xt170/CV_MONTH %s", "9");
system(strexecmonth);
monthflag=1;
}
}
else{
monthflag=0;
}
break;
case 10:
if((diday==25)&&(dihour==0)&&(diminute==0)){
if(monthflag==0){
sprintf(strexecmonth, "sh /u1/xt170/CV_MONTH %s", "10");
system(strexecmonth);
monthflag=1;
}
}
else{
monthflag=0;
}
break;
case 11:
if((diday==25)&&(dihour==0)&&(diminute==0)){
if(monthflag==0){
sprintf(strexecmonth, "sh /u1/xt170/CV_MONTH %s", "11");
system(strexecmonth);
monthflag=1;
}
}
else{
monthflag=0;
}
break;
case 12:
if((diday==25)&&(dihour==0)&&(diminute==0)){
if(monthflag==0){
sprintf(strexecmonth, "sh /u1/xt170/CV_MONTH %s", "12");
system(strexecmonth);
monthflag=1;
}
}
else{
monthflag=0;
}
break;
}
}
}
void intr_hdlr()
{
printf(" End The custom timer\n");
exit(0);
}
int gettime(int limonth, int liday, int lihour, int liminute, int lisecond)
{
char* ls_date;
char* lp_date;
time_t ls_t;
int li_month,li_day,li_hour,li_minute,li_second;
int count;
time(&ls_t);
ls_date = ctime(&ls_t);
lp_date = ls_date+4;
ls_date[7] = '\0';
for(count=0;count<12;count++)
{
if(strcmp(lp_date,tbMon[count][0])==0)
{
li_month=atoi(tbMon[count][1]);
break;
}
}
lp_date = ls_date+8;
ls_date[10] = '\0';
li_day = atoi(lp_date);
lp_date = ls_date+11;
ls_date[13] = '\0';
li_hour = atoi(lp_date);
lp_date = ls_date+14;
ls_date[16] = '\0';
li_minute = atoi(lp_date);
lp_date = ls_date+17;
ls_date[19] = '\0';
li_second = atoi(lp_date);
limonth=li_month;
liday=li_day;
lihour=li_hour;
liminute=li_minute;
lisecond=li_second;
return(0);
}
int myitoa(int myi,char* mya,int length)
{
int n;
int m;
int ii;
char ss[10];
if(length > 10)
return(-1);
ii=myi;
for(n=0;n<length;n++) {
ss[n]=ii%10+48;
ii=ii/10;
if(ii == 0)
break;
}
n++;
for(m=0;m<n;m++)
*(mya+n-1-m)=ss[m];
if(m>=10)
m=9;
*(mya+m)='\0';
return(1);
}
int myltoa(long myl,char* mya,int length)
{
int n;
int m;
long ii;
char ss[15];
if(length > 15)
return(-1);
ii=myl;
for(n=0;n<length;n++) {
ss[n]=ii%10+48;
ii=ii/10;
if(ii == 0)
break;
}
n++;
for(m=0;m<n;m++)
*(mya+n-1-m)=ss[m];
if(m>=10)
m=9;
*(mya+m)='\0';
return(1);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -