CS 140 Midterm Examination Winter Quarter, 2012

Similar documents
CS140 Operating Systems and Systems Programming Midterm Exam

CSE 120 Principles of Computer Operating Systems Fall Quarter, 2001 Midterm Exam. Instructor: Geoffrey M. Voelker

COMP 3361: Operating Systems 1 Midterm Winter 2009

CS140 Operating Systems and Systems Programming

CS140 Operating Systems and Systems Programming Midterm Exam

Stanford University Computer Science Department CS 140 Midterm Exam Dawson Engler Winter 1999

University of California College of Engineering Computer Science Division- EECS. Midterm Exam March 13, 2003 CS162 Operating Systems

MCS-378 Intraterm Exam 1 Serial #:

Student Name: University of California at Berkeley College of Engineering Department of Electrical Engineering and Computer Science

CMPS 111 Spring 2013 Prof. Scott A. Brandt Midterm Examination May 6, Name: ID:

CS 140: Operating Systems and Systems Programming Midterm Exam

CS140 Operating Systems and Systems Programming Midterm Exam

CS 450 Exam 2 Mon. 4/11/2016

Homework #3. CS 318/418/618, Fall Ryan Huang Handout: 10/01/2018

Suggested Solutions (Midterm Exam October 27, 2005)

University of California at Berkeley College of Engineering Department of Electrical Engineering and Computer Science

CROWDMARK. Examination Midterm. Spring 2017 CS 350. Closed Book. Page 1 of 30. University of Waterloo CS350 Midterm Examination.

COS 318: Midterm Exam (October 23, 2012) (80 Minutes)

Midterm Exam #1 February 28, 2018 CS162 Operating Systems

EECE.4810/EECE.5730: Operating Systems Spring Midterm Exam March 8, Name: Section: EECE.4810 (undergraduate) EECE.

COMP 3361: Operating Systems 1 Final Exam Winter 2009

University of Waterloo Midterm Examination Term: Winter Year: 2013

Midterm Exam March 13, 2013 CS162 Operating Systems

ENGR 100 Midterm (CSE Part) Winter 2014

CS 162 Midterm Exam. October 18, This is a closed book examination. You have 60 minutes to answer as many questions

Name: uteid: 1. CS439H: Fall 2011 Final Exam

Computer Science 161

Operating Systems (1DT020 & 1TT802)

Operating Systems Comprehensive Exam. Spring Student ID # 3/16/2006

CS 571 Operating Systems. Midterm Review. Angelos Stavrou, George Mason University

Midterm Exam October 15, 2012 CS162 Operating Systems

OS 1 st Exam Name Solution St # (Q1) (19 points) True/False. Circle the appropriate choice (there are no trick questions).

Midterm Exam #1 Solutions February 28, 2018 CS162 Operating Systems

CS140 Operating Systems and Systems Programming

Midterm Exam #2 Solutions October 25, 2016 CS162 Operating Systems

COMP 300E Operating Systems Fall Semester 2011 Midterm Examination SAMPLE. Name: Student ID:

EECS 482 Midterm (Fall 1998)

Operating Systems Comprehensive Exam. Fall Student ID # 10/31/2013

CSE 451 Midterm 1. Name:

Note that there are questions printed on both sides of each page!

York University Lassonde School of Engineering Department of Electrical Engineering and Computer Science

CS 450 Exam 2 Mon. 11/7/2016

University of Waterloo CS350 Midterm Examination Model Solution

CSE120 Principles of Operating Systems. Prof Yuanyuan (YY) Zhou Synchronization Exercise

CS153: Midterm (Winter 19)

Operating Systems Comprehensive Exam. Spring Student ID # 3/20/2013

ECE469 - Operating Systems Engineering Exam # March 25

Operating Systems Comprehensive Exam. There are five questions on this exam. Please answer any four questions total

(b) External fragmentation can happen in a virtual memory paging system.

First Midterm Exam Solutions October 1, 2018 CS162 Operating Systems

Homework #3. CS 318/418/618, Fall Handout: 10/09/2017

Sample CS 142 Midterm Examination

1. Consider the following page reference string: 1, 2, 3, 4, 2, 1, 5, 6, 2, 1, 2, 3, 7, 6, 3, 2, 1, 2, 3, 6.

CS-537: Midterm Exam (Fall 2013) Professor McFlub

This exam paper contains 8 questions (12 pages) Total 100 points. Please put your official name and NOT your assumed name. First Name: Last Name:

Notes on the Exam. Question 1. Today. Comp 104:Operating Systems Concepts 11/05/2015. Revision Lectures (separate questions and answers)

First Midterm Exam September 28, 2017 CS162 Operating Systems

Midterm Exam Solutions March 7, 2001 CS162 Operating Systems

Comp 204: Computer Systems and Their Implementation. Lecture 25a: Revision Lectures (separate questions and answers)

Question 1. Notes on the Exam. Today. Comp 104: Operating Systems Concepts 11/05/2015. Revision Lectures

STUDENT NAME: STUDENT ID: Problem 1 Problem 2 Problem 3 Problem 4 Problem 5 Total

Midterm I October 11 th, 2006 CS162: Operating Systems and Systems Programming

Operating Systems Comprehensive Exam. Spring Student ID # 2/17/2011

CS 134 Midterm Fall 2006

CS 370 Operating Systems

There are 13 total numbered pages, 7 Questions.

Last Class: CPU Scheduling! Adjusting Priorities in MLFQ!

Midterm Exam #2 April 20, 2016 CS162 Operating Systems

EECS489 Computer Networks, Take-home Makeup Midterm (Winter 2007) due in class Wednesday 3/28

MCS-378 Intraterm Exam 1 Serial #:

CS 134 Midterm Spring 2013

CS 134 Midterm Fall 2006

Last Class: Deadlocks. Today

CS350 Midterm Spring 2012 Page 1

Department of Computer Science Faculty of Engineering, Built Environment & IT University of Pretoria. COS122: Operating Systems

Operating Systems: Quiz2 December 15, Class: No. Name:

CPS 310 midterm exam #1, 2/19/2016

CSE 153 Design of Operating Systems

CSE 451 Midterm Exam May 13 th, 2009

CPS 310 midterm exam #1, 2/17/2017

CSE 153 Design of Operating Systems

University of Waterloo Midterm Examination Term: Winter Year: Solution. begin solution

Outline. TDDC47 Lesson 1: Pintos labs Assignments 0, 1, 2. Administration. A new kind of complexity. The Pintos boot process

Third Midterm Exam April 24, 2017 CS162 Operating Systems

Comp 310 Computer Systems and Organization

Final Exam. COMP Summer I June 26, points

University of Waterloo Midterm Examination Model Solution

Midterm Exam Amy Murphy 19 March 2003

CSC369 Lecture 5. Larry Zhang, October 19,2015

CS162, Spring 2004 Discussion #6 Amir Kamil UC Berkeley 2/26/04

CS-537: Midterm Exam (Spring 2001)

CSCI 346 Final Exam Review Materials

There are 8 total numbered pages, 6 Questions. You have 60 minutes. Budget your time carefully!

Sample CS 142 Midterm Examination

Chapter 6: Process Synchronization

EECE.4810/EECE.5730: Operating Systems Spring 2017

There are 19 total numbered pages, 8 Questions. You have 2.5 hours. Budget your time carefully!

CPSC/ECE 3220 Summer 2018 Exam 2 No Electronics.

Real-Time and Concurrent Programming Lecture 4 (F4): Monitors: synchronized, wait and notify

Spring 2001 Midterm Exam, Anthony D. Joseph

Transcription:

CS 140 Midterm Examination Winter Quarter, 2012 You have 1.5 hours (90 minutes) for this examination; the number of points for each question indicates roughly how many minutes you should spend on that question. Make sure you print your name and sign the Honor Code below. During this exam you are allowed to consult two double-sided pages of notes that you have prepared ahead of time; other than that, you may not consult books, notes, or your laptop. If there is a trivial detail that you need for one of your answers but cannot recall, you may ask the course staff for help. I acknowledge and accept the Stanford University Honor Code. I have neither given nor received aid in answering the questions on this examination, and I have not consulted any external information other than two double-sided pages of prepared notes. (Signature) SOLUTION SET (Print your name, legibly!) (email id, for sending score) Problem #1 #2 #3 #4 #5 Total Score Max 12 10 12 15 35 84-1-

Problem 1 (12 points) Answer each of the following questions briefly (in one or two sentences). (a) Under what conditions does FIFO scheduling result in the shortest possible average response time? Answer: if the jobs happen to arrive in the ready queue with the shortest completion times first (or, as a special case, if all jobs have the same completion time). (b) Under what conditions does round robin scheduling behave identically to FIFO? Answer: if the job lengths are no longer than the length of the time slice. (c) Under what conditions does round robin scheduling perform poorly compared to FIFO? Answer: if the job lengths are all the same, and much greater than the time slice length. (d) In the situation you described in part (c) above, does reducing the time slice for round-robin scheduling help or hurt its performance relative to FIFO? Why? Answer: reducing the time slice increases the average response time. It causes all the jobs to finish closer and closer to the end time: if there are N jobs all the same length L, the first job will finish at approximately N*L (N-1)*T, where T is the length of the time slice. The smaller that T becomes, the later the first job finishes. -2-

Problem 2 (10 points) Suppose two threads execute the following C code concurrently, accessing shared variables a, b, and c: Initialization int a = 4; int b = 0; int c = 0; Thread 1 Thread 2 if (a < 0) b = 10; c = b - a; a = -3; else c = b + a; What are the possible values for c after both threads complete? You can assume that reads and writes of the variables are atomic, and that the order of statements within each thread is preserved in the code generated by the C compiler. Answer: 4, 7, 13, 14, -3-3-

Problem 3 (12 points) Below are several actions that must be carried out to implement dynamic linking for shared libraries. For each of the actions indicate whether the action is carried out by the compiler/assembler, linker, operating system loader (the part of the OS that loads a process into memory and starts its first thread running), or a runtime library that is statically linked into the application. If multiple components share responsibility for the action, explain what each one does. (a) Choose the memory address of the jump table. Answer: linker and loader (the linker determines the virtual address, and the loader determines the physical address) (b) Fill in the jump instructions in the jump table. Answer: runtime library c) Choose the memory address for the shared library code. Answer: runtime library d) Fill in the instructions that jump into the jump table. Answer: compiler and linker -4-

Problem 4 (15 points) The figure below shows the address translation mechanism used for 64-bit mode in Intel x86 processors. Starting with a 48-bit virtual addresses, it uses 4 levels of page table to translate the address to a 52-bit physical address. Each page table entry is 8 bytes long. If the page size is increased, the number of levels of page table can be reduced. How large must pages be in order to translate 48-bit virtual addresses with only 2 levels of page table? Draw the address translation mechanism corresponding to this page size. Answer: 256 KB (2 18 bytes) per page -5-

Problem 5 (35 points) You have been hired by Caltrans to automate the flow of traffic on a one-lane bridge that has been the site of numerous collisions. Caltrans wants you to implement the following rules: Traffic can flow in only a single direction on the bridge at a time. Any number of cars can be on the bridge at the same time, as long as they are all traveling in the same direction. To avoid starvation, you must implement the five car rule : once 5 or more consecutive northbound cars have entered the bridge, if there are any southbound cars waiting then no more northbound cars may enter the bridge until some southbound cars have crossed. A similar rule also applies once 5 or more consecutive southbound cars have entered the bridge. You must implement the traffic flow mechanism in C by defining a structure struct bridge, plus five functions described below. When a northbound car arrives at the bridge, it invokes the function bridge_arrive_north(struct bridge *b) This function must not return until it is safe for the car to cross the bridge, according to the rules above. Once a northbound car has finished crossing the bridge it will invoke the function bridge_leave_north(struct bridge *b) Southbound cars will invoke analogous functions bridge_arrive_south and bridge_leave_south. Use the next pages to write a declaration for struct bridge and the four functions above, plus the function bridge_init, which will be invoked to initialize the bridge You must write your solution in C using the Pintos functions for locks and condition variables: lock_init (struct lock *lock) lock_acquire(struct lock *lock) lock_release(struct lock *lock) cond_init(struct condition *cond) cond_wait(struct condition *cond, struct lock *lock) cond_signal(struct condition *cond, struct lock *lock) cond_broadcast(struct condition *cond, struct lock *lock) Use only these functions (e.g., no semaphores or other synchronization primitives). You may not use more than one lock in each struct bridge. Your solution must not use busy-waiting. If your southbound functions are identical to the northbound functions except that north is replaced with south (and vice versa) in all identifiers, then you can omit the southbound functions and just circle this bullet point. -6-

This page is for your solution to Problem 5. struct bridge int north_waiting; int north_crossing; int north_consecutive; int south_waiting; int south_crossing; int south_consecutive; struct lock lock; struct condition northbound_done; struct condition southbound_done; void bridge_init(struct bridge *b) b->north_waiting = 0; b->north_crossing = 0;; b->north_consecutive = 0; b->south_waiting = 0; b->south_crossing = 0 b->south_consecutive = 0; lock_init(&b->lock); cond_init(&b->northbound_done); cond_init(&b->southbound_done); int bridge_arrive_north(struct bridge *b) lock_acquire(&b->lock); b->north_waiting++; while ((b->south_crossing > 0) ((b->south_waiting > 0) && (b->northconsecutive >= 5)) cond_wait(&b->southbound_done; b->north_waiting--; b->north_crossing++; b->northconsecutive++; b->southconsecutive = 0; lock_release(&b->lock); int bridge_leave_north(struct bridge *b) lock_acquire(&b->lock); b->north_crossing--; if (b->north_crossing == 0) cond_broadcast(b->northbound_done); lock_release(&b->lock); -7-

Additional working space for Problem 5, if needed. int bridge_arrive_south(struct bridge *b) lock_acquire(&b->lock); b->south_waiting++; while ((b->north_crossing > 0) ((b->north_waiting > 0) && (b->southconsecutive >= 5)) cond_wait(&b->northbound_done; b->south_waiting--; b->south_crossing++; b->southconsecutive++; b->northconsecutive = 0; lock_release(&b->lock); int bridge_leave_south(struct bridge *b) lock_acquire(&b->lock); b->south_crossing--; if (b->south_crossing == 0) cond_broadcast(b->southbound_done); lock_release(&b->lock); -8-