调用open()时对输入的无尽请求


#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <iostream>
#include <string.h>
int main(){
int fd;
size_t size;
char name[]="aaa.fifо";
umask(0) ;
if (mknod(name, S_IFIFO | 0666, 0) < 0){  
printf("Can't create FIFOn");
_exit(-1);
}
if ((fd = open(name, O_WRONLY)) < 0){ 
printf("Can't open FIFO for writingn");
_exit(-1);
}
char message[60];
while(true){
message[0] = 0;
std::cin.clear();
std::cin >> message;
if(!strcmp(message,"exit"))
{
printf("Exit to programmn");
break;
}
size = write(fd, message, 60);
if (size < strlen(message)) {
printf("Can't write all string to FIFOn");
_exit(-1);
}
}
close(fd);

return 0;
}

通过键入,我意识到在调用open()时会出现问题。

当我删除循环时同样的麻烦即使在main()开头的cout没有任何工作,但是当你从open()中删除行时,一切都正常工作

我意识到在调用open()时会出现问题。

某些进程必须打开FIFO进行读取,然后您的open()继续。

最新更新