Computer Science 354
Operating Systems

Dickinson College
Spring Semester 2006
Grant Braught

Project #1 - Processes and Shells

Introduction

Resources

Compiling and Running C++ Programs

Part 1 - fork, wait and execv

    In this part of the project you will write several programs that make use of the fork, wait and execv system calls in C++.

  1. Write programs A.cpp, B.cpp, C.cpp, D.cpp, such that when program A is run the following process tree is created:

    Every process should wait for all of its children to complete. Note process D doesn't fork any other processes. It should just announce that it is running, sleep for a little while and then announce that it is done. If you have D sleep for long enough you will be able to use the ps command to verify that you have created the correct process tree.

    The output from running program A should be similar to the following:

    Turn in printouts of your 4 programs as your answer to this question. (Save backup copies, because the next several questions ask you to make some changes to these programs.) Question to think about for discussion in class: can you guarantee that the output will be exactly as given above? If not, why not?
  2. Answer the following questions by modifying your programs from #1 and using the ps command. You will need to use calls to the sleep method in your processes so that you have time to observe the results using ps. You will also need to use some of the options to the ps command in order to see PPID information as well as all system processes (you will be particularly interested in the init process.) Do not turn in programs for this part. In your answers just explain how you modified prgrams C and D, what you did in order to answer the question and what you found.
    1. What happens to process D if you kill process C while it is waiting for process D to complete?
    2. What happens to process C if process D is killed while process C is waiting on it?
    3. What happens to process C if process D completes naturally before process C waits on it?
    4. What happens if process C exits normally while process D is still running?
    5. Based on those observations. What do you think would happen if you ran process A and it were killed while waiting for its child processes B and C? Check your expectations and describe what happens.
    6. What happens if you kill the process for the command shell from which process A was run while process A is still running? Why do you think this is different?

Part 2 - Exending the SimpleShell