/* pipe.C */

#include <iostream>
using namespace std;
#include <unistd.h>

#define DATA "hello world"
#define BUFFSIZE 1024

int rgfd[2];    /* file descriptors of streams */

/* NO ERROR CHECKING, ILLUSTRATION ONLY!!!!! */

main()
{
    char sbBuf[BUFFSIZE];

    pipe(rgfd);    
    if (fork()) { /* parent, read from pipe */
        close(rgfd[1]);   /* close write end */
        read(rgfd[0], sbBuf, BUFFSIZE);
	cout << "-->" << sbBuf << '\n';
        close(rgfd[0]);
    }
    else { /* child, write data to pipe */
        close(rgfd[0]);   /* close read end */
        write(rgfd[1], DATA, sizeof(DATA));
        close(rgfd[1]);
        exit(0);
    }
}
