CS476/576
Assignment #4
Due Midnight,
Wednesday Nov. 17, 2004
Write a C/UNIX program with the following descriptions:
NAME
ipcChain -
A program that creates a chain of processes communicating using
three different interprocess communication mechanisms: pipe, tcp and udp.
SYNOPSIS
ipcChain
<pipe|tcp|udp> <n>
DESCRIPTION
- The
program creates n processes,
process i creates
process i+1, for i=1,
2, ...n-1.
- Process i+1 communicates with process i, for i=1,
2, ...n-1, using either a pipe, a tcp connection or udp
sockets.
- Process i+1 sends its messages to process i, for i=n-1, ...1
- The first process displays
the received messages to the stdout.
- The last process dies after
1 second from the time of its creation.
- When a process
detects the death of its child, it dies after 1 second.
- Upon
the creation of process i it
sends to process i-1 the
message
START: MyNumber=i, MyPID=<pid>,
MyParentPID=<pid>, MyChildPID=<pid>
- Just before the termination
of process i it sends to
process i-1 the message
DONE: MyNumber=i:
Examples of output
% ipcChain
pipe 2
START: MyNumber=1, MyPID=15273, MyParentPID=11134, MyChildPID=15274
START(Last): MyNumber=2, MyPID=15274, MyParentPID=15273
DONE(Last): MyNumber=2
DONE: MyNumber=1
% ipcChain tcp 3
START: MyNumber=1, MyPID=15250, MyParentPID=11134, MyChildPID=15251
START: MyNumber=2, MyPID=15251, MyParentPID=15250, MyChildPID=15252
START(Last): MyNumber=3, MyPID=15252, MyParentPID=15251
DONE(Last): MyNumber=3
DONE: MyNumber=2
DONE: MyNumber=1
% ipcChain udp 4
START: MyNumber=1, MyPID=15311, MyParentPID=11134, MyChildPID=15312
START: MyNumber=2, MyPID=15312, MyParentPID=15311, MyChildPID=15313
START: MyNumber=3, MyPID=15313, MyParentPID=15312, MyChildPID=15314
START(Last): MyNumber=4, MyPID=15314, MyParentPID=15313
DONE(Last): MyNumber=4
DONE: MyNumber=3
DONE: MyNumber=2
DONE: MyNumber=1