web123456

linux system programming fcntl function setting is not blocked

#include<> #include<> #include<> #include<> #include<> #include<sys/> int main(int argc,char *argv[]) { int fd=open("dev/tty",O_RDWR); //The fcntl function sets non-blocking int flags=fcntl(fd,F_GETFL);//Get status flags|=O_NONBLOCK; fcntl(fd,F_SETFL,flags); char buf[256]={0}; int res=0; while(1) { ret=read(fd,buf,sizeof(buf); if(ret<0) { printf("read err"); printf("ret is %d\n",ret); } } }