아래 코드를 사용하여 PIPE를 생성했습니다. 그러나 프로그램이 fd = open(FIFO, O_RDONLY);
으로 실행될 때 잘못된 것이 있습니다. 이 현상은 차단되고 있습니다. 누군가 나에게 조언을 해줄 수 있을까요? 고마워.PIPE 블록 만들기
#include<errno.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<stdio.h>
#define FIFO "/tmp/test"
int main(int argc, char** argv)
{
char buf_r[100];
int fd;
int nread;
if((mkfifo(FIFO, O_CREAT) < 0) && (errno != EEXIST))
{
printf("can not create FIFO\n");
exit(1);
}
printf("Prepare read data\n");
fd = open(FIFO, O_RDONLY);
if(fd == -1)
{
exit(1);
}
while(1)
{
if((nread = read(fd, buf_r, 100)) == -1)
{
if(errno == EAGAIN) printf("No data\n");
}
if(buf_r[0]=='Q') break;
buf_r[nread]=0;
printf("data is:%s\n", buf_r);
sleep(1);
}
}
buf_r [nread] = 0;'nread는 100이고 buf_r의 크기는 100입니다. – joop