0% found this document useful (0 votes)
47 views3 pages

Programming Assignment 1

This document provides instructions for Programming Assignment #1 on advanced operating systems. It asks students to write a C program that creates a binary tree of Unix processes using process creation system calls like fork() and exec(), with each process printing information about its position in the tree, parent process, and children. Students are also asked to list details of the Linux process control block structure and process creation system calls, and modify their program to have child processes print that they are zombies after their parent is killed.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
Download as doc, pdf, or txt
0% found this document useful (0 votes)
47 views3 pages

Programming Assignment 1

This document provides instructions for Programming Assignment #1 on advanced operating systems. It asks students to write a C program that creates a binary tree of Unix processes using process creation system calls like fork() and exec(), with each process printing information about its position in the tree, parent process, and children. Students are also asked to list details of the Linux process control block structure and process creation system calls, and modify their program to have child processes print that they are zombies after their parent is killed.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1/ 3

Advanced Operating Systems, Spring 2009

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

Left child Right child


You won't be drawing a graphical representation, but your program's processes should
print out the information about the tree as follows…

* Running a program on the UNIX/linux shell.


(On Shell)#->./process 3

[1] pid 81142, ppid 48569


[1] pid 81142 created left child with pid 81143
[1] pid 81142 created right child with pid 81144
[2] pid 81143, ppid 81142
[3] pid 81144, ppid 81142
[2] pid 81143 created left child with pid 81145
[3] pid 81144 created left child with pid 81146
[3] pid 81144 created right child with pid 81147
[4] pid 81145, ppid 81143
[2] pid 81143 created right child with pid 81148
[6] pid 81146, ppid 81144
[7] pid 81147, ppid 81144
[5] pid 81148, ppid 81143
[3] right child 81147 of 81144 exited with status 7
[3] left child 81146 of 81144 exited with status 6
[2] right child 81148 of 81143 exited with status 5
[2] left child 81145 of 81143 exited with status 4
[1] right child 81144 of 81142 exited with status 3
[1] left child 81143 of 81142 exited with status 2
Tree ends...

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” .

Note: Programs will be evaluated based on correctness, documentation (have a


comment describing the entire program and comments pointing out key parts of
the code), and efficiency. For any queries related to assignment, you are free to ask
through mail, can contact ahmadhassan@ucp.edu.pk

You might also like