/* Using a pipe to handle interprocess communication: GETP/PUTP #include #include #include #define GET(x) notend=EOF!=(x=getchar()) #define PUT(x) putchar(x) #define pf(a,b,c,d) {c=b;d=a;} error(char *s) { fprintf(stderr, "\n cryptop: %s \n", s);} int piped[2]; #define PUTP(c) if(write(piped[1], &c, sizeof(c))==-1)error("Write failed") #define GETP(c) notend=read(piped[0], &c, sizeof(c))!=-1 main(){ int a,b,c,d,notend; if(pipe(piped)==-1)error("Pipe() failed!"); if(fork()==0){/*child process starts here*/ p2(); }/*end of child*/ else {/* start of parent(!)*/ close(piped[0]); GET(a);GET(b); while( notend ){ pf(a,b,c,d); PUTP(c); PUTP(d); GET(a); GET(b); } }/*end of parent*/ } p2() { int n,m, notend, c; close(piped[1]); GETP(c); while(notend){ /*line*/ for( m=1; notend && m<=10; m++ ){ /*group*/ for( n=1; notend && n<=5; n++ ){ PUT(c); GETP(c); } PUT(' '); } PUT('\n'); } return(0); }