Hi
I was trying to learn pipe but I the program is not giving me the expected output.
The program is as below:
Code:
//#include <iostream>
#include<stdio.h>
#include<stdlib.h>
#include<errno.h>
#include<sys/types.h>
#include<unistd.h>
#include<unistd.h>
#include <string.h>
int main(int argc, char **argv) {
int pfd[2];
char buf[30];
pipe(pfd);
if(fork())
{
printf("\n Child writing to pipe");
write(pfd[0],"Testing Pipe",24);
printf("\n Child exiting\n");
exit(0);
}
else{
memset(buf,0x00,sizeof(buf));
printf("\n Parent Reading");
read(pfd[1],buf,5);
printf("\n PArent REad %s\n",buf);
}
return 0;
}
Can Anybody help me what I am doing wrong?
Thanks