#include <stdlib.h>
#include <errno.h>
#include <stdio.h> //printf()
#include <unistd.h> //pause()
#include <signal.h> //signal()
#include <string.h> //memset()
#include <sys/time.h> //struct itimerval, setitimer()
static struct sigaction osa;
void PrintfMes(int Num,siginfo_t *infop,void *unused)
{
if(infop->si_code!=SI_KERNEL)
return ;
printf("%s\n","hello world\n");
return ;
}
int main()
{
// signal(SIGALRM,PrintfMes);
struct sigaction sa;
sa.sa_handler=PrintfMes;
sigemptyset(&sa.sa_mask);
sa.sa_flags=SA_SIGINFO;
if(sigaction(SIGALRM,&sa,&osa)<0)
{
perror("sigaction()");
exit(1);
}
while(1)
{
struct itimerval tick;
tick.it_value.tv_sec=5;
tick.it_value.tv_usec=0;
tick.it_interval.tv_sec=1;
tick.it_interval.tv_usec=0;
int ret=setitimer(ITIMER_REAL,&tick,NULL);
if(ret!=0)
{
printf("Set timer error.%s \n",strerror(errno));
return -1;
}
pause();
}
// while(1)
// {
// alarm(5);
// pause();
//printf("Wait!\n");
//getchar();
// }
return 0;
}
#include <errno.h>
#include <stdio.h> //printf()
#include <unistd.h> //pause()
#include <signal.h> //signal()
#include <string.h> //memset()
#include <sys/time.h> //struct itimerval, setitimer()
static struct sigaction osa;
void PrintfMes(int Num,siginfo_t *infop,void *unused)
{
if(infop->si_code!=SI_KERNEL)
return ;
printf("%s\n","hello world\n");
return ;
}
int main()
{
// signal(SIGALRM,PrintfMes);
struct sigaction sa;
sa.sa_handler=PrintfMes;
sigemptyset(&sa.sa_mask);
sa.sa_flags=SA_SIGINFO;
if(sigaction(SIGALRM,&sa,&osa)<0)
{
perror("sigaction()");
exit(1);
}
while(1)
{
struct itimerval tick;
tick.it_value.tv_sec=5;
tick.it_value.tv_usec=0;
tick.it_interval.tv_sec=1;
tick.it_interval.tv_usec=0;
int ret=setitimer(ITIMER_REAL,&tick,NULL);
if(ret!=0)
{
printf("Set timer error.%s \n",strerror(errno));
return -1;
}
pause();
}
// while(1)
// {
// alarm(5);
// pause();
//printf("Wait!\n");
//getchar();
// }
return 0;
}