CSCI 4534 - Operating Systems
Final Examination
There are 10 problems in this final examination. Some are easier than
others, so read through all of them before you decide how to allocate
your time to maximize your score. Partial credit will be given when
appropriate, so it is a reasonable strategy to do partial work on all
the problems instead of dedicating too much time on a select few.
The total points you can earn is 110. The examination is graded on a
scale of 0-100, so you have 10 points of optional extra credit.
You have 4 hours to compose your responses on the provided blank
sheets of paper; use additional sheets of paper, as needed. Write
your name and signature on the header of every sheet of paper.
Answer sheets without your name and signature will not be graded.
Write clearly, and use good English. Illegible or unclear
responses will not receive full marks. You may use pencil or pen.
You may use the classroom computer only to review lecture
material, available in the form of powerpoint presentations, or to
access personal notes from a floppy or USB drive (but no other
files). Only one student may use the computer at a time. Remember
to remove your floppy or USB drive when you step away from the
computer.
This is an open book examination. You may refer to your
textbook and personal notes which you took during the course at will,
as well as the classroom computer in the manner described above. You
may not use any other written or electronic materials,
including but not limited to personal laptops, calculators, or cell
phones.
Do not sit right next to another student, especially one who was your
study partner. Similar answers are natural between study partners, so
sitting far apart is the best way to prevent concerns regarding
possible Honesty Code violations.
The Honesty Code of UHCL states: I will be honest in all my
academic activities and will not tolerate dishonesty. You should
work on this examination completely on your own, without consulting
with any other student; you should also report any violations you
observe. Your signature on your answer sheets indicates you agreement
to abide by this policy during this examination.
Processes
Consider the following C program:
int main(int argc, char **argv)
{
printf("%d\n",fork());
}
This program is being executed under a process whose ID is 10. Assume
that the operating system will assign ID 11 to the next process
created. Each of the following are suggested as possible outputs on
the terminal window from which process 10 was started; some
suggestions are feasible (i.e. may happen), some are not (i.e. they
can never happen). For each suggestion, state whether it's feasible or
not and justify your answer.
- [1 point]
10
11
- [1 point]
11
10
- [1 point]
0
11
- [1 point]
11
0
- [1 point]
0
10
- [1 point]
10
0
- [2 points]
011
- [2 points]
10
1
Threads
[6 points] Under pure user threads, the user-level
scheduler cannot preempt one thread to let another run. Instead, a
thread has to explicitly yield control of the CPU to the
user-level scheduler (via a user-level function call into a user-level
library) who can then pass control to another user-level thread. For
example, the Pthreads C-language API includes the function
void pthread_yield();
to achieve this end. Java green threads are also pure user
threads. However, there is no method like the one above in the
Thread
class, nor anywhere else in the JDK. Does that
mean that your Java green threads can never be preempted? If they
cannot, explain why not; if they can, explain at what execution points
preemption of a Java thread is possible.
[2 points] If a Java green thread blocks on I/O, can
another green thread of the same program take over the CPU? Assume the
JVM is assigned a single kernel thread. Justify your answer.
[3 points] List the three ways in which user-level
threads can be mapped to kernel-level threads, and concisely list
the relative advantages of each technique.
CPU scheduling
Consider a set of processes with the following characteristics:
Process
| Burst time
| Arrival time
| Initialization time
|
P1
| 4
| 0
| 1
|
P2
| 7
| 1
| 1
|
P3
| 3
| 2
| 2
|
P4
| 9
| 3
| 2
|
The process initialization time is the cummulative time the
process needs to spend executing on the CPU from the moment it first
starts using the CPU, and until it produces its first response. For
example, with FCFS scheduling,
- P1 starts using the CPU at time 0, and at time 0+1=1
it produces its first response; the response time of
P1 is 1-0=1 since the process arrived at time 0 and
produced its first response at time 1.
- P2 starts using the CPU at time 0+4=4 (after
P1 is done), and at time 4+1=5 it produces its first
response; the response time of P2 is 5-1=4.
- P3 starts using the CPU at time 4+7=11, and at time
11+2=13 it produces its first response; the response time of
P3 is 13-2=11.
- P4 starts using the CPU at time 11+3=14, and at time
14+2=16 it produces its first response; the response time of
P4 is 16-3=13.
The Gantt chart is:
0........3
| 4........10
| 11........13
| 14........22
|
P1
| P2
| P3
| P4
|
The average response time for the above process schedule
under FCFS scheduling is (1+4+11+13)/4=7.25.
- [2 points] What is the average response time for
the above process schedule under SJF scheduling? Show your work,
including the Gantt chart of the schedule.
- [2 points] What is the average response time for
the above process schedule under SRTF scheduling? Show your work,
including the Gantt chart of the schedule.
- [2 points] What is the average response time for
the above process schedule under RR scheduling with a quantum of 1?
Show your work, including the Gantt chart of the schedule.
- [2 points] What is the average response time for
the above process schedule under RR scheduling with a quantum of 3?
Show your work, including the Gantt chart of the schedule.
- [2 points] On page 159, the textbook states
The SJF scheduling algorithm is provably
optimal. Are the above results contradictory,
reaffirming, or irrelevant to the book's claim? Justify your answer.
- [2 points] Based on your results, and ignoring
context-switching overhead (which is worse the smaller the RR
quantum), does a smaller quantum always produce a more responsive
system?
Process sychronization
[11 points] Consider the following proposed solution
to the critical section problem for n processes. Determine
whether it is a correct one, and then justify your answer in the
following manner:
- If it is correct, prove its correctness in a manner similar to
that of section 7.2.1.3 of the textbook.
- If it is incorrect, show a counterexample, i.e. an interleaving
of the instructions executed by the n processes that leads to
a violation of either one (or more) of the mutual exclusion, progress,
or bounded waiting requirements.
The proposed solution is listed below:
- Shared data and their initial values:
enum pstate {idle,want_in,in_cs};
pstate flag[n]; /* flag[0]=flag[1]=...=flag[n-1]=idle */
int turn=0;
- Process structure:
i
=0, 1, ..., n-1.
while (1) {
flag[i]=want_in;
int j=turn; /* j is a variable local to each process */
while (j!=i) {
if (flag[j]==idle) {
j=(j+1)%n;
} else {
j=turn;
}
}
flag[i]=in_cs;
turn=i;
/* critical section */
j=(turn+1)%n;
while (flag[j]==idle) {
j=(j+1)%n;
}
turn=j;
flag[i]=idle;
/* remainder section */
}
Deadlocks
Consider the following snapshot of a system that employs deadlock
avoidance via the banker's algorithm:
Allocation
| Max
| Available
|
| R1
| R2
| R3
| R4
|
P0
| 0
| 0
| 1
| 2
|
P1
| 1
| 0
| 0
| 0
|
P2
| 1
| 3
| 5
| 4
|
P3
| 0
| 6
| 3
| 2
|
P4
| 0
| 0
| 1
| 4
|
|
| R1
| R2
| R3
| R4
|
P0
| 0
| 0
| 1
| 2
|
P1
| 1
| 7
| 5
| 0
|
P2
| 2
| 3
| 5
| 6
|
P3
| 0
| 6
| 5
| 2
|
P4
| 0
| 6
| 5
| 6
|
|
|
- [1 point] What are the contents of the
Need matrix?
- [5 points] Is the system in a safe state? If so,
derive a safe sequence and justify your derivation; if not, explain
why not.
- [5 points] Assuming no fairness policy, can the
system in the above state grant immediately a request from process
P1 for (0,4,2,0)? Justify your answer and show your work.
Memory management
Consider a memory management model that uses segmentation with paging
in the same style as PhysicalController
from assignment
2. Here are the lengths of the five address parts:
- Segment selector (number): 2 bits.
- Segment offset: 2 bits.
- p1: 3 bits.
- p2: 2 bits.
- d: 1 bit.
Answer the following questions, and justify all your answers.
- [1 point] What is the size of a frame, in bytes?
- [1 point] What is the maximum number of segments
a process can have?
- [1 point] What is the maximum size of a segment,
in bytes?
- [1 point] What is the maximum number of page
tables a process can have?
- [1 point] What is the maximum number of entries
that a page table can contain?
- [2 points] What is the maximum size of the address
space of a process, in bytes?
- [1 point] If a process issued linear addresses
(instead of logical addresses), what would be the maximum size of its
address space, in bytes?
- For the following two questions, assume that we cannot change the
number of bits used for d or the segment number and segment
offset. However, we can choose the number of bits used for
p1 and p2. Also, we assume
that all processes always have an address space of maximum size.
[2 points] If we want to minimize the size of kernel
data structures, what is the optimal choice for the number of bits
used for p1?
- [1 point] Given this choice for
p1, what must be the number of bits used for
p2?
Virtual memory
[11 points] The second-chance (SC) algorithm is an
LRU approximation algorithm. Demonstrate by example that it
does not always produce the same result as the LRU
algorithm. Specifically, come up with a page-reference string and
number of frames, and show how SC and LRU produce a different final
set of pages in the frames for the same string; draw diagrams like the
ones on figures 10.9, 10.11, and 10.12 of your textbook. You may
initialize the SC circular queue pointer to point at any frame, but
you have to state your choice clearly.
File systems
[11 points] Consider a disk drive formatted by
MS-DOS. It contains two files:
- File F1, whose data is stored in blocks
0,6,4, and 3 (in this order).
- File F2, whose data is stored in blocks
2,8, and 7 (in this order).
Show the complete contents of the FAT. Assume that the disk
blocks set aside for file data are numbered 0 through 9. Use
-1 to mark unused FAT entries and -2 as the
end-of-file marker.
RAID
Consider 4 identical disk drives whose capacity is 128GB each. We want
to build a RAID system using those drives. What is the maximum
capacity of the RAID system as a whole (i.e. of the new single logical
drive formed by combining the individual disk drives into a RAID)
under each of the following RAID levels?
- [1 point] RAID 0.
- [1 point] RAID 1.
- [2 points] RAID 4.
- [1 point] RAID 5.
- [2 points] RAID 0+1.
- [1 point] RAID 1+0.
If the capacity of each block is 4KB, how many blocks store parity
information under each of the following RAID levels?
- [1 point] RAID 0.
- [1 point] RAID 4.
- [1 point] RAID 5.
Security
Consider a computer system with the following characteristics:
- Below is the system's access matrix:
Domain\Object
| Password file
| Budget file
| Network access
| Email program
| Web browser
| D1
| D2
| D3
| D4
| D5
|
D1
| read*
|
|
|
|
|
|
| switch
| switch
|
|
D2 (Applets)
|
|
| any
|
|
|
|
|
|
|
|
D3
|
|
|
|
|
| switch
|
|
| switch
|
|
D4 (John)
|
|
| HTTP
|
| execute
|
|
| switch
|
|
|
D5 (LuAnn)
|
| read write
| any
| execute
| execute
|
|
|
|
|
|
- The system belongs to the Finance Division of Microsoft, Inc.
- John Cochrane is a Microsoft lawyer, working in this division. He
is not computer-savvy because John skipped his Harvard Law School
computer classes to drink beer with his fraternity brothers.
- A copy of the above access matrix was sent in an internal company
memo to all Microsoft employees. John has his copy of the memo posted
on the wall right over the computer terminal in his office; he doesn't
understand a word of it, of course, but since it is related to his
terminal, he believes he is doing the right thing by posting the
matrix in plain sight.
- John logs onto the system only via his serial terminal
(i.e. never via the network). He just uses his terminal to
browse the internet, which is why the only network access his terminal
has is via the HTTP protocol. John's terminal does not have a floppy
drive, USB port, or any other means to copy data files onto removable
media.
- Austin Powers is John's friend. Austin is an engineer at the
Security Division of Sun Microsystems, Inc., and has his own website
where he publishes game applets. John loves Austin's games, and always
goes to Austin's site to download and run new applets within his web
browser (which he can do because applet code is transferred via HTTP).
- John is assigned domain D4; in other words, when John
starts processes, they all start in domain D4.
- This system executes all applets in domain D2, where
the only operations an applet can execute is read and/or write
arbitrary data to the network (in any protocol, not just HTTP). It
doesn't matter under which domain the web browser is running
(i.e. which user started it).
- The Java security policy of the machine allows applets to
read/write local disk files provided the above access matrix
also allows the operation. In other words, the Java security policy
gives applets the same rights that regular programs have. John needs
this in order to save the state of his games under his account,
whenever Bill Gates pays him a surprise visit.
- John's processes start in domain D4 but they can
arbitrarily switch to domain D3 if they so desire. This is
to make life easier for James Tiberius Kirk, the Microsoft system
administrator. He is an overweight Microsoft employee, and he
configured the access matrix this way because John calls him often to
his office and requests help with his terminal. So James wanted a
quick way to make minor system changes to the computer system while he
was in John's office, and thus save himself walking back and forth
from/to his own office.
- LuAnn Platter is an accountant at Microsoft. She has 15 children
and so prefers to work from home. She can thus connect to this system
via the internet. She is assigned domain D5 when she logs
in.
- The passwords inside the password file are stored in clear text
(i.e. without any encryption). The file is several megabytes long, and
contains the passwords of thousands of users, including LuAnn. Due to
its size, it cannot be sent over the network via the HTTP protocol
(but it can be sent via other protocols); it is also too long for a
person to analyze within a short amount of time.
One day, John goes to his office, and logs into this computer system
via his terminal. At noon, he meets Austin for lunch where John eats a
lot of mít. After lunch, they return to John's office. A few
minutes into their meeting, John suddenly has to leave his office to
go to the restroom. Austin is left alone in the office while John is
gone, and can therefore use John's terminal for less than 2 minutes.
[11 points] During John's absence, can Austin take a
series of non-destructive actions that will eventually lead to him
receiving a copy of Microsoft's budget? If so, list those actions; if
not, explain why not.
© 2004 Apostolos Lerios