select函数测试

#include <stdio.h>
#include
<stdlib.h>
#include
<string.h>
#include
<unistd.h>
#include
<fcntl.h>
#include
<sys/select.h>

int main(int argc,char *argv[])
{

char buf[100] = "";
fd_set rset;
//select集合
FD_ZERO(&rset); //将集合清0
FD_SET(0, &rset); //将标准输入加入到集合中

while(1)
{
#if 0
if(select(1, &rset, NULL, NULL, NULL)>0)
{
printf(
"please input:");
fflush(stdout);
read(
0, buf, 100);
printf(
"buf=%s\n",buf);
}

#else
printf(
"please input:");
fflush(stdout);
read(
0, buf, 100);
printf(
"buf=%s\n",buf);

#endif
}
return 0;
}

  

原文地址:https://www.cnblogs.com/hnrainll/p/2155125.html