#include #include int main() { int children = 12; int p[2]; /* p is pointer to array of two ints */ int rc; int i; rc = pipe( p ); printf( "%d %d\n", p[0], p[1] ); if ( rc < 0 ) { perror( "pipe() failed" ); return 1; } for ( i = 0 ; i < children ; i++ ) { rc = fork(); /* create child */ if ( rc < 0 ) { perror( "fork() failed" ); return 1; } if ( rc == 0 ) { /* child */ int n; char buffer[100]; close( p[0] ); /* don't let this child process access p[0] */ n = read( p[1], buffer, 100 ); buffer[n] = '\0'; printf( "Received: %s\n", buffer ); exit( 0 ); } } /* parent continues here */ { int n; sleep( 15 ); close( p[1] ); n = write( p[0], "<<--FOOTBALL-->>", 16 ); sleep( 30 ); } return 0; }