CS476/576

Assignment #3

Due Midnight, Wednsday   Oct 29, 2003


Write a C/UNIX program with the following descriptions:

NAME

ripple - A  program that creates a set of processes.
SYNOPSIS
ripple n [<file>]
DESCRIPTION

The program creates n processes. Process i creates process i+1, for i=1, 2, ...n-1.
Therefore,  process i is the
parent of process i+1 and  process i+1 is the child of process i, for i=1, 2,..., n-1.

If process i is killed then all other n-1 processes will be terminated.
Therfore killing any process will have a ripple effect on all other processes.

Program Output:

Upon the creation of process i, the program displays the message:

START i: MyPID=<pid1>, MyParentPID=<pid2>, MyChildPID=<pid3>

where <pid1>, <pid2> and <pid3> are processes ids.

Upon the termination of process i, the program displays  one of the following two messages (depending on whether the parent or child exited before the process):

Exit i (becuase PARENT exit)
or
Exit i (becuase CHILD exit)

The program has  one optional argument*: <file>
In addition to displaying the above messages to the stdout the program saves the  messages in 
<file>.

* For  CS476 students: You may not implement this option.



To get a feeling and gain more details about the specificationof this program, execute my own solution under:

/home/cs476/public_html/fall03/assignments/a3/wahab/ripple

Examples:

> ripple
Usage: ripple n [file]

> ripple 7 &
> START 1: MyPID=25747, MyParentPID=23835, MyChildPID=25748
START 2: MyPID=25748, MyParentPID=25747, MyChildPID=25749
START 3: MyPID=25749, MyParentPID=25748, MyChildPID=25750
START 4: MyPID=25750, MyParentPID=25749, MyChildPID=25751
START 5: MyPID=25751, MyParentPID=25750, MyChildPID=25752
START 6: MyPID=25752, MyParentPID=25751, MyChildPID=25753
START(last process) 7: MyPID=25753, MyParentPID=25752

> kill -9 25747
> Exit 2 (becuase PARENT exit)
Exit 3 (becuase PARENT exit)
Exit 4 (becuase PARENT exit)
Exit 5 (becuase PARENT exit)
Exit 6 (becuase PARENT exit)
Exit 7 (becuase PARENT exit)

> ripple 7 &
> START 1: MyPID=25762, MyParentPID=23835, MyChildPID=25763
START 2: MyPID=25763, MyParentPID=25762, MyChildPID=25764
START 3: MyPID=25764, MyParentPID=25763, MyChildPID=25765
START 4: MyPID=25765, MyParentPID=25764, MyChildPID=25766
START 5: MyPID=25766, MyParentPID=25765, MyChildPID=25767
START 6: MyPID=25767, MyParentPID=25766, MyChildPID=25768
START(last process) 7: MyPID=25768, MyParentPID=25767

> kill -9 25768
> Exit 6  (because CHILD exited)
Exit 5  (because CHILD exited)
Exit 4  (because CHILD exited)
Exit 3  (because CHILD exited)
Exit 2  (because CHILD exited)
Exit 1  (because CHILD exited)

> ripple 7 &
> START 1: MyPID=25771, MyParentPID=23835, MyChildPID=25772
START 2: MyPID=25772, MyParentPID=25771, MyChildPID=25773
START 3: MyPID=25773, MyParentPID=25772, MyChildPID=25774
START 4: MyPID=25774, MyParentPID=25773, MyChildPID=25775
START 5: MyPID=25775, MyParentPID=25774, MyChildPID=25776
START 6: MyPID=25776, MyParentPID=25775, MyChildPID=25777
START(last process) 7: MyPID=25777, MyParentPID=25776

> kill -9 25774
> Exit 3  (because CHILD exited)
Exit 2  (because CHILD exited)
Exit 1  (because CHILD exited)
Exit 5 (becuase PARENT exit)
Exit 6 (becuase PARENT exit)
Exit 7 (becuase PARENT exit)

> ripple 7 outfile &
> START 1: MyPID=25801, MyParentPID=23835, MyChildPID=25802
START 2: MyPID=25802, MyParentPID=25801, MyChildPID=25803
START 3: MyPID=25803, MyParentPID=25802, MyChildPID=25804
START 4: MyPID=25804, MyParentPID=25803, MyChildPID=25805
START 5: MyPID=25805, MyParentPID=25804, MyChildPID=25806
START 6: MyPID=25806, MyParentPID=25805, MyChildPID=25807
START(last process) 7: MyPID=25807, MyParentPID=25806

> kill -9 25805
> Exit 4  (because CHILD exited)
Exit 3  (because CHILD exited)
Exit 2  (because CHILD exited)
Exit 1  (because CHILD exited)
Exit 6 (becuase PARENT exit)
Exit 7 (becuase PARENT exit)

> cat outfile
START 1: MyPID=25801, MyParentPID=23835, MyChildPID=25802
START 2: MyPID=25802, MyParentPID=25801, MyChildPID=25803
START 3: MyPID=25803, MyParentPID=25802, MyChildPID=25804
START 4: MyPID=25804, MyParentPID=25803, MyChildPID=25805
START 5: MyPID=25805, MyParentPID=25804, MyChildPID=25806
START 6: MyPID=25806, MyParentPID=25805, MyChildPID=25807
START(last process) 7: MyPID=25807, MyParentPID=25806
Exit 4  (because CHILD exited)
Exit 3  (because CHILD exited)
Exit 2  (because CHILD exited)
Exit 1  (because CHILD exited)
Exit 6 (becuase PARENT exit)
Exit 7 (becuase PARENT exit)