CS476/576

Assignment #3

Due Midnight, Wednesday   October 25, 2006


Write a C/UNIX program with the following descriptions:

NAME

coread  -   Concurrent Readers.

 

SYNOPSIS

coread    <n>    <InputFile>

 

DESCRIPTION

 

The program creates n children processes and all are connected to the parent with a single pipe.

 

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

Sleeps a random amount of time T, where T <= n  seconds and when it wakes up it:

Ø      reads 128  characters from  InputFile  and terminates if there is no more data to read.

Ø      use the pipe to send the PID followed by the data that have been read.

v     The parent reads from the pipe and  produces two files: RecievedFile and PIDCounts:

Ø      The ReceivedFile should be identical to the  InputFile and

Ø      The PIDCounts  contains the number of reads performed  by each child.

 

 

 

 

Example:

 

% coread  10 InputFile

 

% cat PIDReport

 

     12 3431

     12 3437

     12 3439

     13 3433

     13 3434

     14 3430

     14 3435

     14 3436

     15 3438

     16 3432