Consider the following C program written to run under UNIX:
main()
{
int p1[2], p2[2], pid, cc, buf[1];
pipe(p1); pipe(p2); buf[0] = 0;
cc = write( p1[1], buf, 4 );
cc = write( 1, "pre-fork\n", 9 );
if ((pid = fork()) != 0) {
while (buf[0] < 4) {
cc = read( p2[0], buf, 4 );
cc = write( 1, "parent\n", 7 );
buf[0]++; cc = write( p1[1], buf, 4 );
} while (pid != wait(0)) { ; }
} else { /* child */
while (buf[0] < 4) {
cc = read( p1[0], buf, 4 );
cc = write( 1, "child\n", 6 );
buf[0]++; cc = write( p2[1], buf, 4 );
} exit(0);
} exit(0);
}
Note that you need not run this program, but it may be helpful to do so!
To understand this program, you may have to refer to the section 2 of
the UNIX programmer's reference manual, for example, as found at
the
the Ohio State archive or using the man 2 command on most
UNIX systems.
Compared to this notation, the primitives provided by C and UNIX are decidedly low-level. Translate the above C code to this high level parallel programming notation!