select会被信号量中断,比如SIGINT
#include <stdio.h>
#include <fcntl.h>
#include <signal.h>
#include <sys/time.h>
int s_runflag = 1;
void sig_int(int sig)
{
printf("signal int[%d]\n", sig);
}
void sig_quit(int sig)
{
printf("signal quit[%d]\n", sig);
s_runflag = 0;
}
int main()
{
int fd = open("./1.txt", O_CREAT);
signal(SIGINT, sig_int);
signal(SIGQUIT, sig_quit);
while(s_runflag)
{
printf("before select\n");
select(fd+1, NULL, NULL, NULL, NULL);
printf("after select\n");
}
return 0;
}
运行结果
before select
^Csignal int[2]
after select
before select
^\signal quit[3]
after select