CS 321 Spring 2014 > Assignment 1
CS 321 Spring 2014
Assignment 1
Assignment 1 is due at 5 p.m. Tuesday, February 11. It is worth 20 points.
Procedures
You may turn in your work either via Blackboard or in paper form.
To turn in your work via Blackboard, submit answers to the exercises below on UAF’s Blackboard site, under Assignment 1 for this class. A text or wordprocessor file holding the answers to the exercises should be attached to your submission.
To turn in your work in paper form, write up answers to the exercises below, staple multiple sheets together, and put them in my mailbox in the C.S. Dept. office (202 Chapman), or the dropbox just outside the door. Be sure to write your name and the course number on your work.
In either case, I may not look at your homework submission immediately. If you have questions, e-mail me.
Exercises (20 pts total)
- Chapter 1 problems (p. 79), #6.
- Chapter 1 problems (p. 79), #19.
- Chapter 2 problems (p. 170), #1.
Figure 2-2 is on p. 90.
- Chapter 2 problems (p. 170), #10.
Figure 2-12 is on p. 102.
- 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 POSIX 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.
The three code snippets are identical,
except for the line marked with “
<====
”.pid_t p = fork(); if (p) { if (p < 0) _exit(1); int dummystatus; waitpid(p, &dummystatus, 0); } else { _exit(0); // <==== } write(1, "DONE\n", 5); _exit(0);
pid_t p = fork(); if (p) { if (p < 0) _exit(1); int dummystatus; waitpid(p, &dummystatus, 0); } else { // HOWDY! // <==== } write(1, "DONE\n", 5); _exit(0);
pid_t p = fork(); if (p) { if (p < 0) _exit(1); int dummystatus; waitpid(p, &dummystatus, 0); } else { while (true) {} // <==== } write(1, "DONE\n", 5); _exit(0);
- The kernel used in MacOS X, and NeXTSTEP before it,
is not a microkernel.
However it is based on the Mach microkernel—developed
at Carnegie-Mellon in the late 1980s and early 1990s.
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.
- 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.
- Non-Blocking Write.
Suppose we wish to write a function
that works much like the
write
system call, except that it is non-blocking. Explain how you could use thefork
,write
, and_exit
system calls (and no other library functions or system calls) to do this. You may explain in words, or give C++ code for a non-blocking write function. - Non-Blocking Read?
Replacing “
write
” with “read
” in the previous part would not give us a way to write a function to do a non-blocking read; we would need to use other system calls. Why? Hint: If you cannot figure it out, then try to write the code.
- Non-Blocking Write.
Suppose we wish to write a function
that works much like the
- 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.