CS476/576

Assignment #3

Due Midnight, Wednesday   Nov 5, 2008


Write a C/UNIX program with the following descriptions:

NAME

BinTree -  creates a complete binary tree of pipe-connected processes.

 

 

SYNOPSIS

 

        BinTree   <h>

 

 

DESCRIPTION

The program creates a complete binary tree of processes of height <h>.

The minimum (default) value of <h> is 1.

Examples:

    • h =1, then the tree contains 3 nodes: the root and two leafs.
    • h=2, then the tree contains 5 nodes, the root, two internal nodes and four leaves.


Each process, except the root, has a label defined as follows:

Ø    The label of the left (right) child process of root process is 0 (1).

Ø    The label of a process is: P.x, where P the label of its parent and x is 0 (1) for left (right) child.

The root process creates a file F called: BinTreeLogFile.

Each process is connected to its parent with a unix pipe.

 

The root process reads a line from <stdin> and writes it to F  and to its two children. 

A non-leaf child writes the received line from its parent and writes it to its two children, etc.

A leaf process writes the received line preceded by its label to  F the  the  <stdout>.

 

When there are no more lines to read, the root process send SIGQUIT to its two children to and then it exits.

When a non-leaf process receives SIGQUIT, it sends SIGQUIT to its two children and then exits.

A leaf process exits when it receives SIGQUIT.