CS476/576

Assignment #3

Due Midnight, Wednesday   Nov 7, 2007


Write a C/UNIX program with the following descriptions:

NAME

dispatch  -   Parent dispatches work among children.

 

SYNOPSIS

dispatch    <n>   <m>  <InputFile>  <OutputFile>

 

DESCRIPTION

 

The parent creates n (n<= 10) children processes.

Each process i is connected to the parent with PIPEi and is assigned a unique signal  SIGi  to send to its parent (do not assign SIGKILL!).

 

 

Child Process Activities:

 

Each process  i, i= 1, 2,.., n  do the following:

Ø   Logs a NEW record immediately after its creation in file ChildrenLog  in the form:

NEW: i:PID   (e.g., NEW:1:24171  )

 

Ø   Sleeps a random amount of time T seconds (T <=5* n) and when it wakes up it perform the following actions:

 

1.      Sends  SIGi  to its parent.

2.      Reads a block of 128  bytes from the PIPEi

3.      Saves  the Read data in  <OutputFile>.

4.      Logs a Read   record in file  ChildrenLog  in the form:

    Read:i:PID:read#   (e.g., Read:1:24171:4 )

5.      Terminates after reading a total of m reads.

 

Ø   Each child process Logs a DEAD record before its termination in file ChildrenLog in the form:  DEAD:i:PID        (e.g.,  DEAD:1:24171 )

 

 

Parent Process Activities:

 

The parent process performs the following actions:

 

Ø      When it creates a new child i  it Logs  a NEW   record in file  ParentLog  in the form:  NEW:i:PID       (e.g. NEW:1:24171 )

 

Ø      When it gets SIGi  it reads  a block of 128 bytes from  <InputFile> , writes it to PIPEi  and Logs  a SIG   record in file  ParentLog  in the form:

SIG: i:PID         (e.g. SIG:1:24171 )

 

Ø   When child i terminates and there is more data to read from the <InputFile>, the parent creates another child process to replace i  and Logs  a REPL   record in file  ParentLog in the form:

 REPL: i:PID         (e.g. REPL:1:24175  )

 

Ø      When a  child i  terminates, it Logs  a DEAD   record in file  ParentLog  in the form: DEAD: i:PID          (e.g. DEAD:1:24171 )

 

Ø      When there are no more data to read from <InputFile>, the program terminates.

 

The following figure is a general overview of the system:

 

Please see Dr. wahab’s solution is at:

 

http://www.cs.odu.edu/~cs476/fall07/assignments/a3/wahab/dispatch

 

You may use the shell script: check_sh to verify the accuracy of the results.

 

Examples:  they all use InputFile

 

% dispatch 1 10 InputFile OutputFile

 

Results:

 

ChildrenLog_1_10

Prent_Log_1_10

check_1_10

 

 

% dispatch 10 1 InputFile OutputFile

 

Results:

 

ChildrenLog_10_1

Prent_Log_10_1

check_10_1

                                                                     

% dispatch 5 5 InputFile OutputFile

 

Results:

 

ChildrenLog_5_5

Prent_Log_5_5

check_5_5