内容发布更新时间 : 2024/11/1 7:23:02星期一 下面是文章的全部内容请认真阅读。
#include<> #include<> #include<> #include<> #include<> #include<> #include<> /*
ITIMER_REAL SIGALRM ITIMER_VIRTUAL SIGVTALRM ITIMER_PROF SIGPROF */
long unsigned intfibonacci(unsigned int n);
static long p_realt_secs = 0, c1_realt_secs = 0, c2_realt_secs = 0; static long p_virtt_secs = 0, c1_virtt_secs = 0, c2_virtt_secs = 0; static long p_proft_secs = 0, c1_proft_secs = 0, c2_proft_secs = 0; staticstructitimervalp_realt, c1_realt, c2_realt; staticstructitimervalp_virtt, c1_virtt, c2_virtt; staticstructitimervalp_proft, c1_proft, c2_proft;
voidsigFunc_p(intsigno){ switch(signo){ case SIGALRM: p_realt_secs+=10; break; case SIGVTALRM: p_virtt_secs+=10; break; case SIGPROF: p_proft_secs+=10; break; default: break; } }
void sigFunc_c1(intsigno){ switch(signo){
case SIGALRM: c1_realt_secs+=10; break; case SIGVTALRM: c1_virtt_secs+=10; break; case SIGPROF: c1_proft_secs+=10; break; default: break; } }
void sigFunc_c2(intsigno){ switch(signo){ case SIGALRM: c2_realt_secs+=10; break; case SIGVTALRM: c2_virtt_secs+=10; break; case SIGPROF: c2_proft_secs+=10; break; default: break; } }
int main(intargc, char **argv){ long unsigned fib = 0; int pid1,pid2,i; unsignedintfibarg[argc]; int status; //读取命令行参数fibarg for(i=1;i p_realt.it_interval.tv_sec = 0; p_realt.it_interval.tv_usec = 10; p_virtt.it_value.tv_sec = 0; p_virtt.it_value.tv_usec = 10; p_virtt.it_interval.tv_sec = 0; p_virtt.it_interval.tv_usec = 10; p_proft.it_value.tv_sec = 0; p_proft.it_value.tv_usec = 10; p_proft.it_interval.tv_sec = 0; p_proft.it_interval.tv_usec = 10; c1_realt.it_value.tv_sec = 0; c1_realt.it_value.tv_usec = 10; c1_realt.it_interval.tv_sec = 0;c1_realt.it_interval.tv_usec = 10; c1_virtt.it_value.tv_sec = 0; c1_virtt.it_value.tv_usec = 10; c1_virtt.it_interval.tv_sec = 0;c1_virtt.it_interval.tv_usec = 10; c1_proft.it_value.tv_sec = 0; c1_proft.it_value.tv_usec = 10; c1_proft.it_interval.tv_sec = 0;c1_proft.it_interval.tv_usec = 10; c2_realt.it_value.tv_sec = 0; c2_realt.it_value.tv_usec = 10; c2_realt.it_interval.tv_sec = 0;c2_realt.it_interval.tv_usec = 10; c2_virtt.it_value.tv_sec = 0; c2_virtt.it_value.tv_usec = 10; c2_virtt.it_interval.tv_sec = 0;c2_virtt.it_interval.tv_usec = 10; c2_proft.it_value.tv_sec = 0; c2_proft.it_value.tv_usec = 10; c2_proft.it_interval.tv_sec = 0;c2_proft.it_interval.tv_usec = 10; //为父进程启用信号处理程序 signal(SIGALRM,sigFunc_p); signal(SIGVTALRM,sigFunc_p); signal(SIGPROF,sigFunc_p); //设置父进程的定时器,此时父进程开始计时 if(setitimer(ITIMER_REAL, &p_realt, NULL)!=0) printf(\ if(setitimer(ITIMER_VIRTUAL, &p_virtt, NULL)!=0) printf(\ if(setitimer(ITIMER_PROF, &p_proft, NULL)!=0) printf(\pid1=fork(); if(pid1 == 0){ //启用子进程的信号处理程序(禁止父进程的处理程序) signal(SIGALRM,sigFunc_c1); signal(SIGVTALRM,sigFunc_c1); signal(SIGPROF,sigFunc_c1); //设置子进程1的定时器 if(setitimer(ITIMER_REAL, &c1_realt, NULL)!=0) printf(\ if(setitimer(ITIMER_VIRTUAL, &c1_virtt, NULL)!=0) printf(\ if(setitimer(ITIMER_PROF, &c1_proft, NULL)!=0) printf(\