Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

CS 3214 Sample Midterm

Solutions are shown in this style. This exam was given Spring 2016.

1. Abstraction and Protection (12 pts)

a)  (6 pts) An operating system is a software layer that provides abstractions for specific hardware components as well as interfaces that allow user    programs to access these abstractions.

Give one example of such an abstraction, the hardware component(s) it represents, and the interface provided to it!

The abstraction called ______________________________ represents the concrete hardware component(s) _______________

____________________________________________

and it is accessed via the interface called ___________________

____________________________________________ .

There are many possible answers, examples are shown in the table below:

Abstraction

Hardware

Interface

Process/Thread

CPU

Instruction Set,

Process/Thread

Management API

Virtual Memory

Memory

Virtual addresses, Memory Management API

Files

Storage Devices

(disk, etc.)

File descriptor API

Standard I/O

I/O Terminals

File descriptor API

Sockets

Network Interface

Card

File descriptor +

socket API

(Alarm) Signal

Timer Chip

signal(2), SIGALRM

b)  (6 pts) We know that in systems exploiting dual-mode operation, the operating system will receive a trap if a user program attempts to execute a privileged instruction, as for example a C program that  contains a asm(“hlt”) inline asm statement.

To avoid the overheads associated with dual mode operation, such as the cost of mode transitions, evaluate the following two proposed alternative designs and state whether they would provide the same level of protection! Justify your answer!

i.     Outlaw asm” statements so that the programmer cannot insert assembly code that invokes privileged instructions into their programs.

This would not yield the same level of protection since programmers could side- step the compiler by directly writing assembly code; code generated byjust-in- time compilers that directly emit native code would also not be covered.

ii.     Perform a check during the linking and loading process in which the executable is scanned for privileged instructions.

This would provide the same level of protection only if all user code must be loaded by the OS; again, a possible loop hole here would be just-in-time compilation. Closing this loop hole would require outlawing any kind of self-modifying code orjust-in-time compilation, for instance, dont allow segments that are both writable and executable, or changing segments from writable to executable.

A second problem arises with variable-length instruction sets, such as x86, where the analysis would need to verify all possible branch targets as well. Researchers have in fact proposed and built systems that execute in a single mode and restrict user programs to be written in verifiable, type-safe languages.

2. Processes (18 pts)

a)  (14 pts) Assume the following timeline that maps three processes P1, P2, and P3 to their states (READY, RUNNING, BLOCKED). At certain points, processes change the state they are in. In the table below, list one possible reason for why a process may have switched state! Make sure   you do not just say: “P1 transitioned from BLOCKED to READY” or “context switch” – but rather give a reason for why a particular state         transition may have happened! As you consider possible reasons, note    the constraints given by (#), (##), and (*)!

#

P1

P2

P3

Possible reason

BLOCKED

BLOCKED

BLOCKED

Initially, the system is idle

1

READY

BLOCKED

BLOCKED

A timer interrupt wakes up P1 (say from nanosleep())

2

RUNNING

BLOCKED

BLOCKED

The scheduler picks P1 to run

3

RUNNING

READY

BLOCKED

(#) P2 wakes up from network I/O when a packet arrives

4

RUNNING

RUNNING

BLOCKED

The scheduler picks P2 to run (on a second CPU)

5

RUNNING

RUNNING

READY

(##) P3 wakes up because of a communication-related event, say a semaphore signal.

6

RUNNING

READY

READY

P2 is preempted because its time slice has expired (or it calls sched_yield())

7

RUNNING

READY

RUNNING

The scheduler picks P3 to run

8

BLOCKED

READY

RUNNING

P1 starts a read() from a file on disk

9

BLOCKED

RUNNING

RUNNING

The scheduler picks P2 to run (on the CPU on which P1 ran)

10

BLOCKED

RUNNING

BLOCKED

(*) P3 blocks say on a lock or semaphore

11

READY

RUNNING

BLOCKED

P1’s read() from disk, started in #8,