This project involves some programming with Unix processes and pthreads. The goal is not to produce a useful program (as will become obvious) but rather to get more practice programming and debugging with multithreaded code, and to see the differences in using threads and full-fledged processes.
Your task is to design and implement a program which takes an integer argument n from the command line and creates a binary tree of processes or threads of depth n. When the tree is created, each process or thread displays an integer which corresponds to its numbering in a breadth-first traversal of the binary tree, its process and thread ID, its position in the tree relative to its parent (left child or right child), and the parent's process and thread ID. After printing this information, it sleeps for one second, and continues on to the next level of the tree. Each process or thread waits for its children to terminate, and when a child terminates, the parent prints the child's process and thread ID.
Your program should build such a tree using using the fork() and wait() system calls and with threads, specifically pthreads. The output I'm looking for can be found by running my version of the program. FreeBSD/i386 binaries are in /home/faculty/terescoj/shared/cs338. You may write one program which builds either a process or a thread tree based on a command-line flag, or you may have two separate programs.
What to submit
You may work individually or in groups of two for this project. Your submission should be by electronic mail. Use the shar utility to create a single archive which includes the following:
You may work on any unix machine, but it is your responsibility to make sure the submitted code and Makefile works on the CSLab public FreeBSD systems, and that the submitted shar file can be extracted properly (try mailing it to yourself and building your project in a new directory before submitting). All files should be clearly marked with your name, or the names of all group members, if it is a group submission.
Discussion Questions
Grading
Your grade on this project will be based on correctness of the program, documentation (both comments in the source code and the README file), and your answers to the discussion questions.