Final Examination: This Is A Closed Book, Closed Notes, No Calculator Exam
Final Examination: This Is A Closed Book, Closed Notes, No Calculator Exam
Final Examination: This Is A Closed Book, Closed Notes, No Calculator Exam
Final Examination
CS 423 Operating System Design
Spring, 2007
Print your name and ID number neatly in the space provided below; print your name at the upper
right corner of every page.
Name:
Net ID:
Do all parts of all five problems in this booklet. This booklet should include this title page, and 10
question pages. Do your work inside this booklet, using the empty pages and backs of the pages if
needed. Problems are of various difficulty, hence if you do not know the answer immediately,
progress to the next problem and come back to the unsolved problem later.
1. (10 Points) Suppose a user “xyz” has logged into a Linux system and the current directory is
“/home/xyz”. The user types “ls” on the keyboard and then presses enter. Briefly list what happens
inside of the computer system after the “enter” key is pressed. (hint: it will involve almost every major
component of an operating system).
Answer:
1. hardware keyboard interrupt is raised (HW Layer )
2. interrupt handler wakes up keyboard device driver to read the data from the keyboard
(interrupt handler Layer)
3. keyboard device driver returns data to shell program in user mode (device driver Layer)
4. shell program searches $PATH for executable
5. shell creates (forks) a process and executes /bin/ls (process management Layer)
6. the ls process reads current directory (“opendir”, “readdir”) – finds inodes for /home and
for /home/xyz (disk/FS Layer)
a. first do opendir which triggers finding the inodes and caching them in the memory
b. second do readdir – read all files in the directory
7. print out the file entries (FS Layer)
b) How do you make the systems call visible to the user space while implementing a system call?
Answer: Writing the header file for it. For example sched_rate.h from the second MP.
1. (4 Points) Two unrelated processes are running on a normal Linux 2.4.18 box. Each happens to
have an instruction MOV AX, MEM[1000], which stores the content of the AX register into a memory
location with the given address. Suppose the two processes execute the instruction at about the same
time, and they do not have any synchronization mechanism to protect this instruction, what will
happen and why?
Answer: nothing special will happen since the “memory location 1000” is different for different
processes (each process has its own address space).
2. (4 Points) Consider a variable partition memory management system with the following hole sizes
in memory order: 10 KB, 4 KB, 20 KB, 18 KB, 7 KB, 9 KB, 12 KB and 15 KB. Now suppose three
memory allocation requests come that ask for 12 KB, 10 KB and 9 KB, respectively. For the following
two allocation strategies, determine which memory block will be allocated.
(1) Best fit:
3. (5 Points) Suppose that a computer can read or write a memory word in 10 ns. Also suppose that
when an interrupt occurs, all 32 CPU registers, plus the program counter and PSW are pushed onto the
stack. What is the maximum number of interrupts per second this machine can process?
Answer: An interrupt requires pushing 34 words onto the stack. Returning from the interrupt
requires fetching 34 words from the stack. This overhead alone is 680 ns. Thus the maximum
number of interrupts per second is no more than about 1.47 million, assuming no work for each
interrupt.
4. (7 Points) The LRU algorithm can be used in many components of the Operating System (e.g.,
buffer cache in I/O system or page replacement algorithm).
(1) Describe how one may implement LRU for page replacement.
Answer: keep a linked list of all pages in the order of access. Whenever a page is accessed, it is
removed from the list and then inserted at the head of the list.
(2) Implementation of true LRU is rarely used for page replacement. Why is this the case?
Describe two algorithms that can be used to implement approximations of LRU.
2. (4 Points) Two real-time processes are running on a computer. The first one needs to run for 10 ms
every 25 ms; the second one needs to run for 15 ms every 40 ms. Will RMS always work for them?
Answer: The first process uses 0.400 of the CPU. The second one uses 0.375 of the CPU.
Together they use 0.775. The RMS limit for two processes is 2 (20.5 1), which is 0.828, so RMS
is guaranteed to work.
3. (7 Points) Consider a video on demand (VOD) server that has 1000 movies and 3 disks. Some
movies are more popular than others. Currently each movie is stored on a random location on a
random disk. At any given time, a set of clients may be watching the movie (may or may not be
the same movie, and in case two clients are watching the same movie, they may start the movie at
different times). To serve the VOD clients, currently the server periodically reads some video
data for each client, sends the data to the client, and then discards the memory buffer.
Describe several techniques that can be used to improve the performance of this VOD system.
Answer: (1) stripe movie across different disks. (2) on each disk, popular files are placed at
center; (3) keep memory buffers
1. (4 points) In a symmetric multi-processor (SMP) machine, each node has a private hardware cache.
Describe two different ways to achieve cache consistency when one processor writes to data item that
is already cached by some other processor?
2. (6 points) Suppose N threads, each running on one processor, need to access some shared data. If
TSL (Test-and-Set on a shared lock variable) is used to implement synchronization, what kind of
performance problem may occur, (suppose each processor spends relatively long time in the critical
section.) and how can this problem be avoided?
Answer: [see text book, multi-processor, synchronization] basically, each thread should have its own
private lock, TSL on this lock, prevent cache thrashing], a shared token-lock, the private TSL-
protected lock allows for checking the availability of the globally shared token. If not available, then
private lock released, other process can continue to work, and so on. The shared token is used for
accessing the overall shared data.
1. (4 points) Describe how you would implement hard link and symbolic link in a UNIX like file
system
Answer: reference count for hard link, file contains pathname for another file
2. (4 points) What are the cons and pros of stateful vs stateless file servers in a distributed file systems.
Answer: stateful is more efficient, since server already knows about client state (e.g., read offset, etc.)
stateless is more reliable. When either server or client crashes, the other party is not affected. In
comparison, in stateful servers, if client crashes, server needs to detect failure and clean up the state.
3. (4 points) The Google File System is designed to work on thousands of unreliable PCs that may
crash at any time. Give two examples in the design of the Google File System that have taken this fact
into account.
Answer: (1) each chunk is replicated on three chunk servers; (2) whenever master fails and recovers, it
scans all chunk servers to reconstruct the state; (3) master is also replicated; (4) master heartbeat with
chunk servers to detect failures; (4) when write, client pushes data to all replicas, then sends write
request. Primary replica waits till all secondaries have replied, then reply.
4. (4 points) The beginning of a free space bitmap looks like this after the disk partition is first
formatted: 1000 0000 0000 0000 (the first block is used by the root directory). The system always
searches for free blocks staring at the lowest numbered block. So after writing file A, which uses 6
blocks, the bitmap looks like this: 1111 1110 0000 0000. Show the bitmap after each of the following
additional actions (note that the blocks of a file do not need to be allocated contiguously):
(a) File B is written, using 5 blocks
(b) File A is deleted
(c) File C is written, using 8 blocks
(d) File B is deleted
S
Answer: The beginning of the bitmap looks like:
(a) After writing file B: 1111 1111 1111 0000
(b) After deleting file A: 1000 0001 1111 0000
(c) After writing file C: 1111 1111 1111 1100
5. (4 points) In a UNIX-like file system, each i-node has 40 bytes for disk block addresses. Because
the file sizes are expected to be small, only one single indirect block and one double indirect block is
used. What is the maximum file size in this file system (expressed in KBs)? Assume each disk block is
4KB, and disk block addresses are 4 bytes.
40 bytes can store 10 disk addresses. 8 of them point to data blocks. One points to single indirect
block, which points to 1024 data blocks. The last address points to a double indirect block which
points to 1024 single indirect blocks. These can point to 1024^2 data blocks. In total (8+1024 +
1024^2) disk blocks can be addressed within a file. Multiply this by 4K for file size.
3. (5 Points) Consider a system with a trusted server (TS), an application server (AS) and a client C.
Each has a pair of public/private keys. Initially, both AS and C know the public key of TS ( K TSPub) and
TS has already known the public key of AS ( K ASPub). List the steps that C and AS can establish a
secure communication channel (using symmetric key encryption). The communication between any
two parties should not be visible to a third party.
Answer: (1) C sends its public key to TS, encrypted using TS’s public key
(2) TS sends AS’s public key to C, encrypted using C’s public key
(3) C generates a secret key, sends this key to AS, encrypted using AS’s public key
(4) AS and C can now exchange data securely.
The above does not consider authentication. I.e., when AS received secret key from client,
may want to authenticate client. AS can ask C to send some passwd, encrypted using AS’s
public key;
Use the following notations in your answer: A for Alice, B for Bob, Ka and Kb are the secret keys that
Alice and Bob, respectively, shares with the KDC (key distribution center). Kab is the session key that
needs to be established between Alice and Bob.