Programming Assignment 1
Programming Assignment 1
Programming Assignment # 1
Instructions
Work on this assignment individually. You may discuss it with your friends, but don’t copy.
Due Date
This assignment is due by email to ahmadhassan@ucp.edu.pk on March 24, 2009, 11:00 PM.
Your submission mail should have the subject “Programming Assignment # 1”. Any type of
late submission will not be accepted. Put text part of your (*.c) files in a Word or PDF file.
This file should be named registration_ number.doc or registration_number.pdf
Objective
This assignment will better acquaint you with the Linux/Unix Process creation, process states,
and transitions between states. You will also learn how to use fork(), wait() and exec() system
calls in your programs.
The Assignment
1) Go through the Linux source code and find the main PCB data structure (struct_task). List all
of its members. If the member is a pointer to a structure, then also list the members of that
structure. For each member, give a brief (one or two line) description of the PCB data items.
2) Give a list of various Linux system calls that can be used in process creation and management.
Also give a single line description of each. (For help see man pages)
3) Write a C program that creates a "binary tree" of Unix/Linux processes. Call your
program process.c and make sure that your coded file should be properly indented.
Your program should take a single command-line parameter which specifies the
number of levels in the binary process tree. Each process should be assigned a number
corresponding to its position in a level-order traversal of the tree.
Given a height of 3, the tree can be thought of as this binary tree, where the parent-child
links are not explicitly stored by your program but are part of the UNIX process
hierarchy. The tree should look something like this:
main(), Parent
Note that each line of output is indented according to the depth of the node in the
process tree and begins by printing the traversal position of the process that prints it.
Your program's processes should produce output in the following situations:
a. When each process is created, it should print its traversal position, its pid (process
ID, obtained using getpid(2)) and ppid (parent process ID, obtained using
getppid(2)).
b. After a process spawns a child process, it should print its own (not the new child's)
traversal position, its own pid, and the pid of the newly-spawned child along with
an indication of whether this child forms its "left" or "right" subtree.
c. When a child exits (using exit(3)), it should provide its traversal position as its exit
status. This value should be obtained by the parent when it calls waitpid(2) and
printed along with the parent's traversal position, whether the terminated child is a
left or right subtree, the parent's pid, the terminated child's pid and the exit status,
which should be the child's traversal position.
d. Try to kill any of the last level parent process (it should be other than main ( )) by
using kill() system call and after checking their child status output a message from
child processes “I am a Zombie process” .