为了账号安全,请及时绑定邮箱和手机立即绑定

作业社区

探索学习新天地,共享知识资源!

0 提交作业
0 布置作业
0 满分作业
得分 95
学习任务

别摸我的键盘 的学生作业:

write.c #include #include #include #include #include #include #include #include #define PIP_PATH "./pip" int main(int argc, const char *argv[]) { int ret; int fd; int rbytes; char buffer[64]; struct pollfd pfds; pfds.fd = 0; pfds.events = POLLIN; fd = open(PIP_PATH, O_RDONLY); while(1){ ret = poll(&pfds, 1, 500); if(ret == -1){ perror("select()"); exit(EXIT_FAILURE); }else if(ret == 0){ printf("timeout !\n"); }else if(ret > 0){ if(pfds.revents & POLLIN){ rbytes = read(fd, buffer, sizeof(buffer)); if(rbytes > 0){ printf("select io content is %s\n", buffer); } close(fd); break; } } } return 0; } read.c #include #include #include #include #include #include #include #define PIP_PATH "./pip" int main(int argc, const char *argv[]) { int ret; int fd; char buf[] = "hello select io"; ret = access(PIP_PATH,F_OK); if (ret == -1) { mkfifo(PIP_PATH,0644); } fd = open(PIP_PATH, O_RDWR); if(fd == -1){ perror("open()"); exit(EXIT_FAILURE); } char arr[64]; while(1){ printf("please input continue\n"); fgets(arr, sizeof(arr), stdin); if(strncmp(arr, "write",5) == 0){ break; } sleep(1); } int wbytes; wbytes = write(fd, buf, strlen(buf) + 1); if(wbytes < 0){ perror("write()"); } while(1){ printf("please input continue\n"); fgets(arr, sizeof(arr), stdin); if(strncmp(arr, "quit",4) == 0){ break; } sleep(1); } close(fd); return 0; }

微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号