• Description:
    Like exercise 3, a process tree is created according to argv[]. Each process when created will print a line to show its label, pid, and ppid. However the order is not specified. A pipe should be created between parent and its child. The parent writes and the child reads. The root process reads from stdin a char and `broadcast' to its children via the pipes. And the char is flowed down to every node. The process with its label equal to the input char will show a message, including its label, the number of times the char received.
  • Deadline: 2010 Apr 22 00:05am
  • Put your file(s) under ~/usp-982/exer5
  • Examples :
                      shell
                        | 
                        a
                       / \
                      b   e
                     / \   \
                    c   d   f
    $ ./a.out ddduduudduuu abcdef
    I'm c, my pid=2760, and my ppid=2759
    I'm f, my pid=2762, and my ppid=2761
    I'm d, my pid=2763, and my ppid=2759
    I'm e, my pid=2761, and my ppid=2758
    I'm a, my pid=2758, and my ppid=2460
    I'm b, my pid=2759, and my ppid=2758
    a                                                <---- from stdin 
    hello, i'm a, my pid is 2758, counted 1 times    <---- root answers
    a                                                <---- again
    hello, i'm a, my pid is 2758, counted 2 times
    b                                                <---- from stdin
    hello, i'm b, my pid is 2759, counted 1 times    <---- sending via pipe to b
    b
    hello, i'm b, my pid is 2759, counted 2 times
    c
    hello, i'm c, my pid is 2760, counted 1 times
    e
    hello, i'm e, my pid is 2761, counted 1 times
    e
    hello, i'm e, my pid is 2761, counted 2 times
    q                                                <---- exit peacefully
    $