Remarks

The purpose of this practical is to allow a process to multiplex I/O, that is to say, in our case, to "listen" several file descriptors to which data can arrive. For this, we will establish a set of processes with one "master" and seceral slaves. Slaves send data and master is waiting at any time, in a passive waiting.

Exercise 1 - the slave

In less than 10 minutes (not kidding), write the program repeat, which takes two arguments: a message and a time (in microseconds), the program will display the message at regular intervals (in an infinite loop). To avoid the problem of buffering, use write(). Use usleep() for the delay.

Exercise 2 - Multiplexer

Then write the master. It will first performs several fork(), to start multiple instances of repeat, with different parameters, and redirecting the output of each program to a pipe (one pipe per instance). The program must listen to all the pipes in parallel, and when data is displayed on a pipe, it should display them on the standard output (by prefixing the PID of the process, for example). In order to multiplex the inputs, use the system call select().

Exercise 3 - less selective with Paul

Same exercise with the system call poll().