#include<unistd.h> 2 #include<signal.h> 3 #include <stdio.h> 4 void handler() 5 { 6 signal(SIGALRM,handler); 7 alarm(5); 8 printf("Hello/n"); 9 /* 让内核做好准备,一旦接受到SIGALARM信号,就 执行 handler*/ 10 }/*这段函数的执行时间不计算在for循环的时间之内*/ 11 12 int main() 13 { 14 int i; 15 handler(); 16 for(i=1;i<21;i++){ 17 printf("sleep %d .../n",i); 18 sleep(1); 19 } 20 }
#include <stdio.h> 2 #include <time.h> 3 #include <unistd.h> 4 5 6 int main() 7 { 8 time_t starttime; 9 starttime = time(NULL); 10 printf ("%d/n",(int)starttime); 11 } 12