나는 두 개의 기능을 가지고있다 작가()과 독자(). writer() 함수에서 파이프에 메시지를 쓰고 reader() 함수에서 읽는 중입니다. 내가 직면하고있는 문제는 메시지가 파이프에 쓰여지고 있지만 읽을 수 없다는 것입니다. 어쩌면 독서를 위해 파이프를 여는 데 문제가있을 수 있습니다. 코드는 다음과 같습니다 :리눅스에서 파이프 사이의 통신
#include<iostream>
#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
using namespace std;
//edit
int fifo = mkfifo("/tmp/mypipe", S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH);
void writer()
{
char message[] = "this is a message";
int fd;
fd = open("pipe" , O_WRONLY);
write(fd , message , sizeof(message));
cout<<"message wrote: "<<message<<"\n"; // gives output
} // message wrote: this is a message
void reader()
{
char buffer[100];
int fd;
fd = open("pipe" , O_RDONLY);
read(fd , buffer , 100);
cout<<"message is: "<<buffer<<"\n"; // gives output
} // message is:
int main()
{
writer();
reader();
return 0;
}
디버깅했습니다. 그리고 나는 fifo가 올바르게 작성되지 않았다고 생각합니다. 이 문제를 해결하는 방법을 모르겠습니다. 도움이 더 필요합니다.
어떤 도움 주셔서 감사합니다.
writer/reader를 호출하기 전에 main 메서드에서 fifo를 만듭니다. –
main()에서 fifo를 만들려고 시도했는데 출력을 보냈습니다 : message wrote : 이것은 메시지 메시지입니다 : – user2831683
main()에서 fifo를 만든 후 미안 해요, 나는 리더/라이터 함수에서 fifo의 이름을 변경하지 않았습니다. , 지금 바뀌었고, 그것은 훌륭하게 작동했습니다. 도와 줘서 고마워. – user2831683