Docsity

Midterm Exam with Solution for Operating Systems | CS 3204, Exams of Operating Systems

Toggle sidebar
bg1
CS 3204 Operating Systems Midterm Fall 2004
1
V
I
R
G
I
N
I
A
P
O
L
Y
T
E
C
H
N
I
C
I
N
S
T
I
T
U
T
E
A
N
D
S
T
A
T
E
U
N
I
V
E
R
S
I
T
Y
U
T
P
R
O
S
I
M
Instructions:
• Print your name in the space provided below.
• This examination is closed book and closed notes. No calculators or other computing devices may be used.
• Answer each question in the space provided. If you need to continue an answer onto the back of a page, clearly
indicate that and label the continuation with the question number.
• If you want partial credit, justify your answers, even when justification is not explicitly required.
• There are 10 questions, priced as marked. The maximum score is 100.
• When you have completed the test, sign the pledge at the bottom of this page and turn in the test.
• Note that either failing to return this test, or discussing its content with a student who has not taken it is a
violation of the Honor Code.
Do not start the test until instructed to do so!
Name Solution
printed
Pledge: On my honor, I have neither given nor received unauthorized aid on this examination.
signed
pf3
pf4
pf5

Partial preview of the text

Download Midterm Exam with Solution for Operating Systems | CS 3204 and more Exams Operating Systems in PDF only on Docsity!

V

IR

G IN

IA

PO

LYTECHNIC IN ST IT U TE

A N D ST A (^) TE (^) UNIVE

RS

IT

Y U (^) TPROSIM

Instructions:

  • Print your name in the space provided below.
  • This examination is closed book and closed notes. No calculators or other computing devices may be used.
  • Answer each question in the space provided. If you need to continue an answer onto the back of a page, clearly indicate that and label the continuation with the question number.
  • If you want partial credit, justify your answers, even when justification is not explicitly required.
  • There are 10 questions, priced as marked. The maximum score is 100.
  • When you have completed the test, sign the pledge at the bottom of this page and turn in the test.
  • Note that either failing to return this test, or discussing its content with a student who has not taken it is a violation of the Honor Code.

Do not start the test until instructed to do so!

Name Solution

printed

Pledge: On my honor, I have neither given nor received unauthorized aid on this examination.

signed

  1. [6 points] Briefly describe the role the trap instruction plays, from the perspective of a user program.

When a user program calls a system function, the user-accessible function is merely a stub that sets the system into kernel mode and then invokes the trap instruction in order to call the actual system function. The trap instruction searches the trap table for the address of the entry point of the matching actual system function and then issues an unconditional branch to that address.

  1. [6 points] When the trap instruction was introduced, it was suggested that it might not be a good idea for a user program to be able to access the trap table (index) directly. Give an example of an undesirable possibility if a user program could modify the contents of the trap table.

In general, if a user program could access the trap table directly then it could call protected system functions without first setting the system to kernel mode. In particular, if a user program could modify entries in the trap table it could “hijack” system calls by substituting addresses of user code for those of protected system functions.

  1. [6 points] Assume that it is important to prevent user programs from executing certain instructions. Describe one particular way in which hardware support might be provided to implement such restrictions.

The hardware can include a mode bit to distinguish whether privileged code or user code is executing. The mode bit would only be altered via a privileged instruction.

  1. [12 points] List six items that should be included in or linked to the process control block (process descriptor) for a user process.

process id id of process owner

process page map process priority

process status registers process data registers

  1. [12 points] Consider the simple hold/ready/run/block state transition scheme for process scheduling. Draw the state diagram, showing all the possible transitions. Label each transition with a brief, precise description of an event that might cause a process to make that transition.
  2. [12 points] Consider a system that uses the SJN (shortest job next, no timesharing) strategy for scheduling jobs. Complete the table below to show the relevant statistics if the given set of jobs is executed on such a system.

Job CPU Need Wait time Finish time 0 50 20 70

This is straight from the text and lectures.

  1. [12 points] Consider the use of virtual memory versus the use of only real (physical) memory. Briefly describe two different major advantages of using virtual memory from the perspective of the user of an operating system.

One advantage is that most processes that are eligible to run will be allocated less physical memory than they would if only real memory were used. That means that more processes can be in the ready-run cycle at once, increasing the potential level of multi-tasking.

Another advantage is that virtual memory makes it possible to execute processes whose address space is much larger than the amount of real memory available in the system.

  1. Consider the execution of a process on a system that uses 32-bit addresses and demand paged virtual memory with 4096- byte pages.

a) [4 points] What is the maximum number of frames of physical memory that the system could support? Express your answer as a power of 2.

Since the page size equals 2^10, the page offset must be represented using 10 bits. That leaves 22 bits to represent the frame number, and so there cannot be more than 2^22 frames.

b) [8 points] Suppose a process running on this system generated a relative address of 0x12345678. Describe how that would be translated into the proper physical address.

The address is first decomposed into a page number and offset; given the information above, the page number would be 0x12345 and the offset would be 0x678.

The page number must be mapped to a frame number in which the page is actually loaded. (This may require servicing a page fault, but that is not really part of the address translation.)

The frame number is then concatenated with the offset to obtain the proper physical address.