Write a C/UNIX program with the following descriptions:CS476/576
Assignment #4
Due Midnight, Tuesday Nov 6, 2001
NAME
pipeline - A program that creates a chain of processes connected with pipes.SYNOPSIS
pipeline [N]DESCRIPTION
The
program creats N
processes (default value of N is
4) and each process is connected to its next process with two pipes as
shown in Figure .
Upon the creation of the Nth process (the last process), it will send a message in the lower pipeline to the 1st process indicating to the user to start providing input.Any line typed by the user will travel across the upper pipeline from the 1st to the Nth process and then travel across the lower pipeline from the Nth to the 1st process to be displayed back to the user. Therefore every line typed be the user will be displayed back after a round trip through the upper and lower pipelines. Each process introduces a 1 second delay in the upper pipeline, i.e., a message will return back after roughly N seconds.
When the user types CTRL-D, the processes are terminated in the reverse order of their creation, i.e., the Nth process dies first and the 1st process dies last.
To get a feeling and gain more details about the specification
of this program, execute my own solution under:
/home/cs476/public_html/fall01/assignments/a4/pipelineExamples:
> pipeline 3
START: TotNumber=3, MyNumber=1, MyPID=17198, MyParentPID=13803, MyChildPID=17199
START: TotNumber=3, MyNumber=2, MyPID=17199, MyParentPID=17198, MyChildPID=17200
START(last process): TotNumber=3, MyNumber=3, MyPID=17200, MyParentPID=17199
Process 2: got <- Please Input (type CTRL-D to finish)Process 1: got <- Please Input (type CTRL-D to finish)
Please Input (type CTRL-D to finish)
Old Dominion University
Process 1: got -> Old Dominion UniversityProcess 2: got -> Old Dominion University
Process 3: got -> Old Dominion University
Process 2: got <- Old Dominion University
Process 1: got <- Old Dominion University
Old Dominion University
DONE(last process): MyNumber=3
DONE: MyNumber=2
DONE: MyNumber=1
----------------------------------------------------------------
> pipeline 5
START: TotNumber=5, MyNumber=1, MyPID=9932, MyParentPID=13803, MyChildPID=9933
START: TotNumber=5, MyNumber=2, MyPID=9933, MyParentPID=9932, MyChildPID=9934
START: TotNumber=5, MyNumber=3, MyPID=9934, MyParentPID=9933, MyChildPID=9935
START: TotNumber=5, MyNumber=4, MyPID=9935, MyParentPID=9934, MyChildPID=9936
START(last process): TotNumber=5, MyNumber=5, MyPID=9936, MyParentPID=9935
Process 4: got <- Please Input (type CTRL-D to finish)Process 3: got <- Please Input (type CTRL-D to finish)
Process 2: got <- Please Input (type CTRL-D to finish)
Process 1: got <- Please Input (type CTRL-D to finish)
Please Input (type CTRL-D to finish)
CS476
Process 1: got -> CS476Process 2: got -> CS476
Process 3: got -> CS476
Process 4: got -> CS476
Process 5: got -> CS476
Process 4: got <- CS476
Process 3: got <- CS476
Process 2: got <- CS476
Process 1: got <- CS476
CS476
DONE(last process): MyNumber=5
DONE: MyNumber=4
DONE: MyNumber=3
DONE: MyNumber=2
DONE: MyNumber=1
---------------------------------------------------------------------
> pipeline 1
START(last process): TotNumber=1, MyNumber=1, MyPID=9988, MyParentPID=13803
Please Input (type CTRL-D to finish)
Norfolk, virginia
Process 1: got -> Norfolk, virginiaNorfolk, virginia
DONE(last process): MyNumber=1
------------------------------------------------------------------------------
> pipeline
START: TotNumber=4, MyNumber=1, MyPID=10092, MyParentPID=13803, MyChildPID=10093
START: TotNumber=4, MyNumber=2, MyPID=10093, MyParentPID=10092, MyChildPID=10094
START(last process): TotNumber=4, MyNumber=4, MyPID=10095, MyParentPID=10094
START: TotNumber=4, MyNumber=3, MyPID=10094, MyParentPID=10093, MyChildPID=10095
Process 3: got <- Please Input (type CTRL-D to finish)Process 2: got <- Please Input (type CTRL-D to finish)
Process 1: got <- Please Input (type CTRL-D to finish)
Please Input (type CTRL-D to finish)
Computer Science
Process 1: got -> Computer ScienceProcess 2: got -> Computer Science
Process 3: got -> Computer Science
Process 4: got -> Computer Science
Process 3: got <- Computer Science
Process 2: got <- Computer Science
Process 1: got <- Computer Science
Computer Science
DONE(last process): MyNumber=4
DONE: MyNumber=3
DONE: MyNumber=2
DONE: MyNumber=1
>