Operating Systems--Spring 2011
Home | | Schedule | |
Assignments | | Notes
Project 2: Processes
Part A: Learning to Fork/Wait/Exec
Part A Due date: Thursday, Feb 24
In this part of the project, you need to learn how to use the fork,
wait, and exec commands.
You should develop a C++ program, named process.cc. Let's
call the parent process executed by the program
Process A. Process A creates
two child processes: Process B and Process C.
Process B also creates
two child processes: Process D and Process E.
Each process should have an
output announcing that it has started execution. Have the life of
each of these processes be long enough (e.g. 30 sec) so you can observe
them while they are still executing. You can increase the lifetime of a process
by using the sleep( ) function:
sleep(int n);
Invokes the sleep command, which causes the process to wait for n seconds.
When each process wakes up from sleeping, it should terminate itself.
Use the process program to answer the following questions:
-
(a) Run the process program in the background (use &) and use the ps command, likely
to determine the ID of each process and its parent (PID and PPID). Copy and paste
the output of ps -l to a text editor and save it as
process_ps.txt. (You will turn this in).
Use the ID's to draw a diagram of the process tree that your program generates. Make sure
to indicate the ID of each process on your diagram, and make the ID's and parent-child
relationships consistent with the information in your process_ps.txt file.
For the next questions, run your program in the background, and try to kill one process
at a time to see what will happen. To kill a process, find its pid using the
ps command.
You can then kill it using the command:
(Read the manual page on process status, i.e., man ps, and learn
how to interpret the
meaning of each column in the output of the ps -l command. Also read the man page
on kill.)
- (b) If a parent process is killed, what happens (if anything) to
its child processes? Do they stay alive? If so, what happens to their PPID?
- (c) Suppose a parent is going to wait on a child via the
wait command and the child is killed. That is, the parent has not
yet executed the wait command. What happens (if anything)
to the child process? What happens (if anything)
to the parent process? (Note: You may have to insert an extra sleep( ) command
in the parent to make sure you can kill the child before the parent waits).
- (d) If a child's sibling process is killed, what happens (if anything)
to the child process?
- (e) Suppose a process executes another process via one of the exec
commands (e.g., execlp), does the PID of the process change? (Hint: You might
want to exec a long running process, e.g. sleep. Use execlp( ) for this one).
Be as precise as possible when discussing the answers to these four questions.
CAUTION: Before you log out or try another test execution, always use ps to ensure
that all the processes you have previously created are no longer executing.
Note: You will need the following include files for process.cc:
#include <sys/wait.h>
#include <iostream>
Turning in Part A:
- A printout of the files, process.cc and
process_ps.txt
- A diagram (i.e. question a) of the processes generated by process.cc
- Written (typed) answers to questions b - e.
- Submit the files process.cc and
process_ps.txt using submit:
~csci346/bin/submit csci346 project2A
- process.cc, process_ps.txt and associated questions will be graded on this date
and are worth approximately one third of the total project two grade.
- If you do not turn in the required checkpoint files
(process.cc, process_ps.txt, question answers,
then 10% of the total project grade will be deducted for each day late until a third off is reached.
Home | | Schedule | |
Assignments | | Notes
Computer Science 346--Operating Systems
Last Modified: February 18, 2011