#include #include "code.h" /* prototypes for l3_read and l3_write */ int l3_read(int, char *, int); int l3_write(int, char *); /* This test program just creates a couple of pipes, forks and then has the child process use the first pipe to read from the parent, and the second pipe goes from the child to the parent. The parent process then writes a string using l3_write, the child reads using l3_read and displays the result. Questions to netprog@cs.rpi.edu */ int main() { char buf[100]; /* for the string the parent reads */ int p[4]; /* will hold pipe descriptors */ int cid; /* create two pipes */ if ((pipe(p)<0) || (pipe(p+2)<0)) { printf("Error creating pipes\n"); exit(1); } if (fork()==0) { /* The child process - set up read from the first pipe */ cid = create_communication_id(p[0],p[3]); if (cid==-1) { printf("ERROR\n"); exit(1); } /* child writes */ if (l3_write(cid,"Netprog Rules!") <0) { printf("Error writing\n"); exit(1); } } else { /* The parent process - set up write to the first pipe and read from the second */ cid = create_communication_id(p[2],p[1]); if (cid==-1) { printf("ERROR\n"); exit(1); } /* parent reads */ if (l3_read(cid,buf,100) < 0) { printf("Error reading\n"); exit(1); } printf("MESSAGE RECEIVED WAS <%s>\n",buf); } }