标签:int nal family heartbeat tar sigalrm handler size handle
void signalHandler(int signo)
{
switch (signo){
case SIGALRM:
printf("Caught the SIGALRM signal!\n");
handleHeartbeat();
break;
}
}
void startHeart() {
/*struct itimerval {
struct timeval it_interval; *//* 第一次之后每隔多长时间 *//*
struct timeval it_value; *//* 第一次调用要多长时间 *//*
};
struct timeval {
long tv_sec; *//* 秒 *//*
long tv_usec; *//* 微秒,1秒 = 1000000 微秒*//*
};*/
signal(SIGALRM, signalHandler);
struct timeval tv_interval = {0, HEART_EXPIRE}; /*第一次之后每隔多长时间 */
struct timeval tv_value = {5, 0}; /* 第一次调用要多长时间 */
struct itimerval it;
it.it_interval = tv_interval;
it.it_value = tv_value;
setitimer(ITIMER_REAL, &it, NULL);
}
标签:int nal family heartbeat tar sigalrm handler size handle
原文地址:http://www.cnblogs.com/wxmdevelop/p/7816214.html