CS 471

Due Midnight, Thursday Feb 14, 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 is composed of two children, the first is “Male” and the 2nd is “Female

 

The program has two options:

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

-c  The program creates all four pairs to run concurrently and then waits for all processes of the 4 pairs to terminate.

 

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

         

          P1: shared memory

P2: sockets

          P3: pipe

          P4: shared file

 

ü The  parent process 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.

 

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

 

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 male process waits 4 seconds before reading the female reply, prints it to the tty, waits a random time   T <= 10 seconds and then exits.

 

 

ü 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

ü The female process waits a random time  T where  4 <= T <=10 seconds and then exits.

 

 

You may execute my solutions at:

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

Example