February 22, 2006
Coverage:
[USP] Chapter 7
Base Case: Token Ring of One Process
- process communicates to itself through a pipe
- notice data written using printf is buffered
Now n=2
- extending a ring of one process to one of two processes is
fairly straightforward
- now we need two pipes
- parent's standard input read from standard output of child
- child's standard input read from standard output of parent
Extending Ring to Arbitrary Number of Processes
- easily extended
- #pipes necessary = #processes
- still only 1 array of size 2 necessary for pipe file descriptors
- resembles process chain
- i.e., each process only forks once
-
in-class exercise: coding infrastructure necessary for
token ring with an arbitrary number of processes
- take #processes n as a command-line argument
- done in <65 loc, including all of the error checking code
References
[USP] K. A. Robbins and S. Robbins. UNIX Systems Programming: Concurrency,
Communication, and Threads. Prentice Hall, 2003