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

#include <sys/wait.h> 

#define STDOUT	1
enum {READ, WRITE};

int main(int argc, char *argv[])
{
	int fd[2];
	FILE *f;
	char *buffer;
	int status;
	int p_id;

	if(pipe(fd) < 0) {
	    perror("Pipe creation");
	    return -1;
	}

	p_id=fork();
	if(p_id < 0) {
	    perror(argv[0]);
	    return -1;
	} else if(!p_id) {
    	    dup2(fd[WRITE], STDOUT);
	    close(fd[WRITE]);
	    close(fd[READ]);
	    execl("/bin/echo", "echo", "Hello_parent", NULL);
	    perror("Executing /bin/echo");
	    return -1;
	}
	wait(&status);
	close(fd[WRITE]);

	f=fdopen(fd[READ], "r");
	
	buffer=(char *)malloc(80);
	fscanf(f, "%s", buffer);

	fclose(f);

	printf("Child said: \"%s\"\n", buffer);
	free(buffer);

	return 0;
}