Linux select函数
作者:互联网
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
标签:quit,函数,int,signal,printf,sig,Linux,select 来源: https://blog.csdn.net/zzy570384336/article/details/121925884