Description:

This 7-th exercise is similar to the 5-th one.
However, this time you have to create a bi-directional ring and the root has to handle two signals.

When receiving the first signal, the root does the same operation in exercise 5. That is, generates a random number, sends it to the ring, receives six numbers from the ring, and finally prints them out.

When receiving the second signal, the root first generates his random number, then sends it to the ring in ANOTHER direction. Each process when receiving the number from the ring in ANOTHER direction, will also generate a number and send it to ring in ANOTHER direction. Finally the root read a number from ring to clean up the data.

Each process when receiving a number from the ring in ANOTHER direction, prints his number out. The number read from the ring is just for synchronization.

The `select()' or `poll()' is necessary in your implementation since you have to monitor two files.

Here is the possible output.

      ----------- 1st window ----------------
$ ./a.out 
Hello, I'm 11374. Please Send me Signals. 
47 8 19 24 35 40              <----- got SIGUSR1, generate six numbers
I'm 11374. I have rolled 20   <----- got SIGUSR2, each process shows his number
I'm 11379. I have rolled 43   <-----   .....
I'm 11378. I have rolled 9    <-----   .....
I'm 11377. I have rolled 24   <-----   .....
I'm 11376. I have rolled 39   <-----   .....
I'm 11375. I have rolled 5    <-----   .....
7 21 36 45 11 25              <----- got SIGUSR1, generate six numbers
I'm 11374. I have rolled 17   <----- got SIGUSR2, each process shows his number
I'm 11379. I have rolled 1    <-----   .....
I'm 11378. I have rolled 13   <-----   .....
I'm 11377. I have rolled 25   <-----   .....
I'm 11376. I have rolled 37   <-----   .....
I'm 11375. I have rolled 49   <-----   .....
^C
$ 
      ----------- 2nd window ----------------
$ kill -USR1 11374
$ kill -USR2 11374
$ kill -USR1 11374
$ kill -USR2 11374
$