CS550 Assignment 1 Creating and Destroying a Process Hierarchy solution

$30.00

Original Work ?
Category: You will Instantly receive a download link for .ZIP solution file upon Payment

Description

5/5 - (4 votes)

Objectives

  • Learn how to create and terminate processes.
  • Learn about process hierarchy.
  • Learning to use system calls fork(), exec(), wait(), getpid(), getppid()
  • Practice using command-line arguments and recursion.

Description

You are being asked to write a program that will recursively create a process hierarchy tree that is H levels deep, print out the process tree information as the tree is being created, and then systematically terminate all the processes in the tree. Here are the detailed requirements:

  1. Your program should accept two command-line arguments Hand C that describe the structure of the process tree. The argument H is the height of the tree and C is the number of child processes belonging to each internal node of the process tree.
  2. Upon starting up, your program should first print the following information:
  3. (pid): Process starting
  4. (pid): Parent’s id = (ppid)
  5. (pid): Height in the tree = (value_of_H_from_command_line_argument)
  6. (pid): Creating (value_of_C_from_command_line) children at height (H-1)

In the above output, you should replace pid by the process id of the current process and ppid by the process id of the parent process.

  1. Next, if the height H is greater than 1, your program should create C child processes using fork(), and wait for all of the children to complete using the wait()system call.
  2. Once all the child processes (if any) have terminated, your program should quit by printing.
  3. (pid): Terminating at height (H).

Parent must not quit before ALL child processes terminate.
Also, parent must call wait() ONLY AFTER CREATING ALL CHILDREN. (Think why?)

  1. What should each child process do while the parent waits? Recursion! Each of the child processes should use the exec()system call to run exactly the same program image as the parent. The only difference should be that the command-line argument received by the child proceses from the parent (via the exec() system call) should be H-1for height and C for number of children.
    (NOTE: Recursion in this step can also be done without using exec(), via straightforward function calls. But you are REQUIRED to use exec() to start the child program image and pass arguments to it. Learning about exec() is one of the goals of this assignment.)
  2. Make the output more readable by neatly indenting the print statements above to match height of each process in the process heirarchy. (Do this at the end. Its worth only 5 points, but makes the TA’s life easier while grading).

Grading Guidelines

This is how we will grade your assignment during the demo. So please prioritize your work accordingly.

 

20 – Correctly creating a hierarchy of processes with arbitrary H and C using fork() and exec().

 

20 – Correctly terminating the hierarchy for arbitrary H and C using wait()/waitpid().

 

10 – Recursion is implemented using exec() (and NOT using usual function calls)

 

10 – Parent process wait()s for child processes ONLY after it creates ALL child processes.

 

10 – Parent process does not terminate before ALL child processes terminate.

 

10 – Error Handling

Most important part here is to make sure that you check and handle the errors

returned by ALL systems calls used in your program. Also check for other common

error conditions in your program. But don’t go overboard with error checking.

We will NOT try to intentionally break your code with bad input that’s irrelevant

to the assignment’s goal.

 

5  – Indented formatting for output of processes at different heights in the hierarchy

 

5 – Makefile, Compilation without errors, README

 

 

Total points = 90

Hints

  1. The entire program is likely very small, no more than a few tens of lines of code at most, if you think through it carefully.
  2. Use manpages to check the usage details of different system calls.
  3. Do this assignment as a regular user, NOT as root, to avoid corrupting your system accidentally.
  4. Use the command “kill -9 (pid)” to kill one process. Use “killall (program_name)” to kill all processes starting with a certain name. Use “kill -9 -1” to kill all processes owned by the current user (do this ONLY as a normal user, NEVER as root).
  5. Remember to terminate *all* the processes you create. If implemented incorrectly, you can easily end up writing a program that forks indefinitely. That’s called a “fork bomb”, and you don’t want to handle cleaning up the mess.
  6. If at all possible, try NOT to do this assignment on bingsuns machines. If you do something slightly wrong, you can end up with a fork bomb on the bingsuns server. The system administrators there won’t like it and they will automatically disable your account. It will be a royal pain for you to get it reactivated. (This has happened before). Use a regular user account in your own virtual system image in the G-7 lab, so that you have root access to kill your processes, or to reboot the machine, if needed.