I am leaning c program . And i have a program shown below.
in testpipe.c
#include<stdio.h>
#include<string.h>
#include<unistd.h>
#include<fcntl.h>
const char *fifo ="/tmp/test";
int main(){
int fd = open(fifo, o_wronly);
char *text ="hello this is the text";
while(1){
write(fd,text,strlen(text));
}
return 0;
}
i created a pipe in bash using below command
mkfifo /tmp/test
then execute
./testpipe
the program will be running and writing to the pipe /tmp/test
now in another terminal
if i type
tail -f /tmp/test
I don't find any result
But i tried to do
cat /tmp/test
Able to get the result result continuously
What is the difference between these two.
Apart from it if i terminate cat /tmp/test , it kill the ./testpipe why?
I tried to experiment the above case using a bash. But the result was different First terminal i tried like
mkfifo /tmp/test
while true; do
echo $(date) >/tmp/test
done
Second terminal
When i type
cat /tmp/test
I get output not continuously.
But when i try
tail -f /tmp/test
Getting continuously the output. If i try to terminate tail or cat , It is not killing the while loop.
- What is the difference between these two approach, what i am missing?