int main(void){
fd_set rfds;
struct timeval tv;
int retval;
FD_ZERO(&rfds);//清空文件描述符
FD_SET(0,&rfds);//设置文件描述符
tv.tv_sec = 3;
tv.tv_usec = 0;
while(1){
retval = select(1,&rfds,NULL,NULL,&tv); //第一个参数是最大fd+1
if(retval == -1)
perror("select err\n");
else if(retval){
printf("data is ready\n");
if(FD_ISSET(0,&rfds)){//文件描述符是否发生变化
printf("0fd is ready\n");
exit(0);
}
}else
printf("No data\n");
}
return 0;
}