//直接上demo
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
#include <cerrno>void signalrm_fn(int sig)
{printf("alarm!\n");alarm(2);return;
}
int main(void)
{//信号触发函数 ,当该线程触发到SIGALRM信号之后,便会执行signalrm_fn函数//而 函数 alarm(2) 表明运行到当前,计时2秒,2秒后发出信号SIGALRM//然后执行函数signalrm_fn//注意啊,程序 跑2秒是很快的,所以要将进程的状态设置为挂载signal(SIGALRM,signalrm_fn);alarm(2);while(1){int ret = pause();printf("the return is :%d\n",ret);if(errno == EINTR){printf("errno == EINTR\n");}}return 0;
}
alarm!
the return is :-1
errno == EINTR
alarm!
the return is :-1
errno == EINTR
alarm!
the return is :-1
errno == EINTR
######################################
被打断施法,后面继续更新
感觉这一块涉及很多底层 进程 通信
Q@@@QQ