CS 471

Due Midnight, Thursday Feb 7, 2013


 

Write a C or C++ program called FourPairs  described below.

 

Usage Syntax:

  

FourPairs [-s | -c]

  

Where:

   -s sequential

   -c concurrent

 

ü The program creates four pairs of children processes P1, P2, P3 and P4.

Each pair Pi composed of two children, the first is “Male” and the 2nd is “Female

 

The program has two options:

-s option: The program creates the four pairs sequentially one at a time and waits for two process of each pair to terminates before starting the next pair.

-c option: The program creates all the four pairs to run concurrently and then waits for all  the 8 processes to terminate.

 

ü The children of pair  Pi  communicate using the following IPC methods:

         

          P1: shared memory

P2: sockets

          P3: pipe

          P4: shared file

 

ü The  program prints the following after the creation of each pair:

 

Pair Pi: Using “IPC method”

Created Son PID of Pair Pi.

Created Daughter PID of Pair Pi.

 

and prints the following after the termination of each process:

 

Daughter PID  of Pair Pi EXITED after (t) seconds.

        OR

Son PID of Pair Pi EXITED after (t) seconds.

 

ü The male process of  the  pair writes the following message to the female process:

          How are you my sister?

    Your brother PID

    Date

 

ü The female process of the pair waits 1 second before reading the message, prints it to the tty, waits 2 seconds before replying with the following message:

I am fine my brother.

Your sister PID

Date

     It waits a random time between 4 and 10 seconds and then exits.

 

ü The male process waits 4 seconds before reading the female reply, prints it to the tty, waits a random time  <= 10 seconds and then exits.

 

ü The parent waits  for both children and  then prints the following messages in any order:

Daughter PID of Pair Pi Exited.

Son PID of Pair Pi Exited.

You may execute my solutions at:

http://www.cs.odu.edu/~cs471w/spring13/assignments/a1/wahab

Example