Hello guys,
I created a named pipe on my Ubuntu machine using the command
Now I am trying to read from that pipe in a C program doing the following.
Code:
void listen() {
int fp;
char buf[255];
fp = open("mypipe", O_RDONLY);
if(fp == -1) {
printf("Could not open the pipe\n");
}
while(1) {
read(fp, buf, sizeof(buf));
printf("%s", buf);
}
close(fp);
}
When I write to the pipe using the following command
Code:
echo "Hello" > mypipe
The C program just prints the text continuously without any break. Is it something wrong with my program or is it how the pipes work? And I can't check the returned string and see if it matched the previous read.
Thanks for your help.