CS 1550 Practice Mid-Term Exam Questions

 

These are practice questions similar in form to those that may appear on the mid-term. They are intended to help you prepare to answer questions of varying formats, not as a comprehensive review of the material. Keeping up with the readings has been strongly emphasized in class, and you should have read through the discussion of working sets.

 

If you are unsure of the meaning of a question, feel free to ask the instructor for clarification (this is acceptable during the exam too). On a similar note, it is often useful to explicitly state any assumptions you make.

 

OS History and Introduction

 

Q: Name the OS architecture that most closely matches the following statements.

 

The most common OS architecture (e.g. Linux,and Windows).

Answer: Monolithic

 

This architecture is what you get if you focus only on resource

management, leaving abstraction as a later step.

Answer: VM

 

QNX, VxWorks, and Mach are all ______ architecture OSs.

Answer: Microkernel

 

Q: What is the single most important criteria an interactive system's scheduler tries to minimize?

Answer: Average response time.

 


Scheduling

 

Q: “Shortest Job First is optimal.” Explain this statement, and explain why SJF is therefore not used instead of “sub-optimal” scheduling policies.

Answer: The trick here is to consider “optimal at doing what?” It is optimal at increasing completion rate, but what about average turnaround time if starvation occurs? fairness? response time?

 

Q: For the following list of jobs, (job id, admission time, required CPU time),assume round-robin scheduling with a quantum of 4 time units. Assume an overhead of 1 time unit per context switch – between different processes. Assume new jobs are admitted at the tail of the queue, and jobs admitted at the same time are queued in the order listed below.

a)    Order of execution.

b)    The average and individual turnaround times.

c)     Average time spent waiting for the CPU.

d)    Recalculate a) through c) for a quantum of 8 time units.

 

Jobs:

(A, 0, 16), (B, 0, 12), (C, 2, 24), (D, 3, 8), (E, 4, 4), (F, 6, 12)

 

 


IPC and Deadlocks

 

Q: Name the four conditions for deadlock. Are these conditions necessary and/or sufficient?

 

Q: Implement a binary semaphore using an atomic exchange instruction (XCHG).  Give the code for both P(s) and V(s).

 

Q: Fix the following code sample

 

/** Producer Consumer Using Semaphores **/

 

semaphore mutex = 1;

semaphore empty = N;

semaphore full = 0;

int buffer[N];

 

void producer() {

int item;

while(TRUE) {

item = produce_item();

down(mutex);

down(empty);

insert_item(item,buffer);

up(full);

up(mutex);

}

}

 

void consumer() {

int item;

 

while(TRUE) {

down(mutex);

down(full);

item = remove_item(buffer);

up(empty);

up(mutex);

}

}

 

/** Producer Consumer Using Semaphores **/

 

Answer: Hint – consider the order of mutex and counting semaphores. A deadlock can easily happen here. Limit the mutex-protected region to the bare minimum that needs to be protected (around insert_item() and remove_item() to be precise).

 

 

Q: In a physical computer system, what can you do in terms of hardware settings to prevent code from being interrupted?

Answer: Disabling interrupts.

 

Q: What is a race condition? Explain by providing a scenario where one can occur (e.g. when updating shared variables).

 

Q: A system provides a “print(file,printer)” command to send a file to one of two possible printers. Attempting to use this function from two processes at once causes garbled output, and users don’t care which printer the output is sent to. Using any clear pseudocode, show how you would write a “safe_print(file)” function using semaphores to print safely to any available printer.

 

 

 

Memory Management & Page Replacement

 

 

 

Q: A system has 45MB of RAM. If we have twenty active processes, and 64-bit page table entries, how much space is used by page tables in this system.

a) using 4KB pages

 b) using 8KB pages

 c) using 1KB pages

 d) using a two-level page table with 4-bit first-level index. [this requires an assumption about memory usage per process, assume a fixed no. of pages per process].

 e) an inverted page table (again, simply assume 64-bit PTEs)

 


Q: Given the following page access string, count the page faults for a memory capacity of 4, 8, and 10 pages.

Access sequence: 0, 1, 2, 3, 0, 1, 4, 0, 1, 2, 3, 4, 5, 6, 3, 2, 1, 0


a) using LRU: 

A: page faults for memory of 4 frames are in boldface: 0, 1, 2, 3, 0, 1, 4, 0, 1, 2, 3, 4, 5, 6, 3, 2, 1, 0

A: pages in memory: -,-,-,-   0,-,-,-   0,1,-,-   0,1,2,-   0,1,2,3   0,1,2,3   0,1,2,3   0,1,4,3   0,1,4,2    0,1,3,2   4,1,3,2  
4,5,3,2    4,5,3,6    2,5,3,6    2,1,3,6    2,1,3,0

 b) using Clock

c) using FIFO

 

 

Q: For the sequence from the last question, what is the maximum working set size for that particular sequence?

Answer: It’s simply the total access set size, seven pages in this case.



Q: Define and give an example of Belady's anomaly.

A: from the book.




Disks and I/O


Q: list the three main delays in getting data from  disk, in increasing average delays (or increasing importance, since the more delay, the more important it is)

A: transfer delay, rotational delay, seek delay.

Q: What does the acronym DMA stand for?  Describe what is the advantage of a system that has a DMA over a system that has no DMA


A: Direct Memory Access:  in a system with DMA, the CPU can run applications without being involved in the transfer of data from a device to main memory.


Q: if all subcomponents of  system use the bus to get data from memory and the CPU needs data from memory to run the application, why does using a DMA allow for higher performance?


A: after a chunk of memory was read (say 4KB) into cache, the CPU will not read anything from memory until a cache miss was detected.


Q: Describe the organ-pipe distribution and mention why it is a good tool increase the performance of disks.


A: placing the most used blocks of data close together in order to reduce the seek time, which is the most important delay in disk performance.  the organ-pipe distribution places data this way, using a histogram and allowing the most used blocks of data to be in the same track, the next most used blocks in the next tracks, etc.


Q: what is the sequence of software layers that are traversed from the time a user needs to read a disk block until the time the data is available to the user (from library call to the return from the library call).  among the layers are:
a) libraries,   b) page replacement algorithms.  c) ISRs, d) Device-independent OS software, e) data placement algorithms, f) de-framentation software, g) device drivers, h) controllers, i) device itself


A: libraries  --> Device-independent OS software --> device drivers --> controller --> device --> ISR --> device drivers --> Device-independent OS software --> libraries.



Q: Let there be the following requests for data blocks in tracks number 100, 175, 51, 133, 8, 140, 73, and 77 and let the head position be in track number 63.  What is the number of tracks that will be traversed with the following disk scheduling algorithms (answer only those that make sense):


a) FIFO 

A: 646 tracks

b) LIFO
A: 623 tracks
c) LRU

d) second chance
A: c) and d) are page replacement algorithms
e) SCAN
A: 238 tracks
f) C-Look

A: 322 tracks


Q: what is and what is the main shortcomings of the SSTF disk scheduling algorithm?


A: shortest seek time first algorithm looks at the queue of requests and givest highest priority to the request with the shortest seek time (that is, closest track to the current position of the read-write head)
it may starve some requests when requests are arriving dynamically