#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

main()
{
	int pid,pfd[2];
	char buf[80];
	if(pipe(pfd)==-1)
	{
		perror("pipe");
		exit(1);
	}
	pid=fork();
	if(pid<0)
	{
		perror("fork");
		exit(1);
	}
	else if(pid==0)
	{
		close(pfd[1]);
		if(read(pfd[0],buf,80)>0)
			printf("Message from child:%s\n",buf);
		close(pfd[0]);
		exit(0);
	}
	else
	{
		close(pfd[0]);
		if(write(pfd[1],"Pipe is a useful tool!",23)!=-1)
			printf("Parent is writing the message!\n");
		close(pfd[1]);
		wait(NULL);
		exit(0);
	}
}
