CS 321 Spring 2012
Assignment 1
Assignment 1 is due at 5 p.m. Tuesday, February 7.
It is worth 25 points.
Procedures
This assignment is in two parts.
The first (A) is a pair of NetRun problems,
which should be done in NetRun, in the usual way.
The second (B)
are short-answer problems.
Answers to these should be
e-mailed
to
ggchappell@alaska.edu,
using the subject
“SA1”.
- I may not read your homework e-mail immediately.
If you wish to discuss the assignment (or anything else)
with me, send me a separate message with a different subject line.
Exercises (25 pts total)
Exercise A — Two NetRun Problems
See
NetRun: CS 321 HW1.
You will need to obtain a NetRun account,
if you do not already have one.
Note: These should be easy.
They are to be done entirely in NetRun;
do not e-mail me the answers.
Exercise B — Short Answer Problems
- Give an example of a virtual something
that differs significantly from an actual something.
- When we make a system call,
we are usually wanting to execute code that does something
the current process is not allowed to do.
What mechanism is used to solve this problem,
and how does it work?
- System Call Actions.
In each part, you are given some C++ code
involving *ix system calls.
Assume that the code compiles.
If the code is executed, and none of the system calls fails,
what will happen?
Indicate what output will result, and
when (if ever) each process will terminate.
(Note that the three code snippets are identical,
except for the line marked with “
<====”.)
pid_t p = fork();
if (p)
{
int dummy;
waitpid(p, &dummy, 0);
}
else
{
_exit(0); // <====
}
write(1, "DONE\n", 5);
_exit(0);
pid_t p = fork();
if (p)
{
int dummy;
waitpid(p, &dummy, 0);
}
else
{
while (true) {} // <====
}
write(1, "DONE\n", 5);
_exit(0);
pid_t p = fork();
if (p)
{
int dummy;
waitpid(p, &dummy, 0);
}
else
{
// HOWDY! // <====
}
write(1, "DONE\n", 5);
_exit(0);
- Parent Process.
- What is a “parent process”?
- What *ix system call returns the PID
of the parent of the current process?
(I do not think I have told you;
it certainly is not in the lecture notes.)
- The kernel used in MacOS X, and NeXTSTEP before it,
is not a microkernel.
However it is based on the Mach microkernel.
What considerations most likely led the developers
at NeXT & Apple to move away from the use of
a microkernel in their OSs?
(You have to guess, of course.
Make a good guess.)
- Multiprogramming generally
results in more efficient processor usage
than would result from a single process.
That is, if there are multiple processes running,
then the processor generally spends less of the time idle
than if only once process is running.
Why is this?
- Non-Blocking I/O.
All the I/O we know how to do so far is blocking I/O,
meaning that the process doing the I/O enters a blocking state
until the I/O is finished.
As a result, I/O functions do not return until the I/O is complete.
An I/O function that does not wait for the I/O to complete before
returning,
is non-blocking.
- Explain how you could use the
fork,
write, and _exit system calls
(and no other library functions)
to do a non-blocking write.
You may explain in words, or
give C++ code for a non-blocking write function.
- This simple technique does not allow us to easily
do a non-blocking read.
Why not?
- The Linux kernel stores its process table
as a doubly linked list of process control blocks
(each of which is of type
task_struct).
It could have used an array instead of a doubly linked list.
Give one advantage of a doubly linked list over an array,
and one advantage that would have been gotten by using an array
over a doubly linked list.