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

Similar documents
University of Waterloo CS350 Midterm Examination Model Solution

University of Waterloo Midterm Examination Term: Winter Year: 2013

CS350 Midterm Spring 2012 Page 1

University of Waterloo Midterm Examination Model Solution CS350 Operating Systems

Spring CS 170 Exercise Set 1 (Updated with Part III)

First Midterm Exam September 28, 2017 CS162 Operating Systems

CS350 Midterm Spring 2012 Page 1

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

Sections 01 (11:30), 02 (16:00), 03 (8:30) Ashraf Aboulnaga & Borzoo Bonakdarpour

Computer Science 161

University of Waterloo Midterm Examination Model Solution

CSE 451 Midterm Exam May 13 th, 2009

CS140 Operating Systems and Systems Programming Midterm Exam

CS350: Final Exam Review

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

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

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

Midterm Exam October 15, 2012 CS162 Operating Systems

ENGR 3950U / CSCI 3020U Midterm Exam SOLUTIONS, Fall 2012 SOLUTIONS

CPS 310 first midterm exam, 2/26/2014

Midterm Exam Solutions and Grading Guidelines March 3, 1999 CS162 Operating Systems

Lecture. DM510 - Operating Systems, Weekly Notes, Week 11/12, 2018

CS4411 Intro. to Operating Systems Exam 1 Fall points 10 pages

CPS 310 first midterm exam, 10/6/2014

Midterm Exam March 13, 2013 CS162 Operating Systems

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

Midterm Exam #1 February 28, 2018 CS162 Operating Systems

CS 333 Introduction to Operating Systems. Class 3 Threads & Concurrency. Jonathan Walpole Computer Science Portland State University

CS140 Operating Systems and Systems Programming

Midterm - Winter SE 350

CS-537: Midterm Exam (Spring 2001)

Midterm I February 28 th, 2019 CS162: Operating Systems and Systems Programming

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

Synchronization Spinlocks - Semaphores

CS 333 Introduction to Operating Systems. Class 3 Threads & Concurrency. Jonathan Walpole Computer Science Portland State University

Synchronization I. Jo, Heeseung

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

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

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

CSE 410 Final Exam 6/09/09. Suppose we have a memory and a direct-mapped cache with the following characteristics.

CMPS 111 Spring 2003 Midterm Exam May 8, Name: ID:

Midterm Exam March 3, 1999 CS162 Operating Systems

CPSC/ECE 3220 Fall 2017 Exam Give the definition (note: not the roles) for an operating system as stated in the textbook. (2 pts.

Problem Set 2. CS347: Operating Systems

Midterm - Winter SE 350

CPS 110 Midterm. Spring 2011

First Midterm Exam Solutions October 1, 2018 CS162 Operating Systems

Eastern Mediterranean University School of Computing and Technology Department of Information Technology. ITEC202 Operating Systems

CSE 451: Operating Systems Winter Lecture 7 Synchronization. Steve Gribble. Synchronization. Threads cooperate in multithreaded programs

Concurrency: Mutual Exclusion (Locks)

Lecture 9: Midterm Review

CS3MH3/6MH3 Final 2005 Page 1 COMP SCI 3MH3/6MH3. Day Class Duration of examination: two hours McMaster University Final Examination April 2005

CS153: Midterm (Winter 19)

CSC 1600: Chapter 6. Synchronizing Threads. Semaphores " Review: Multi-Threaded Processes"

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

Chapter 6: Process Synchronization

Memory Management - Demand Paging and Multi-level Page Tables

CS 537: Introduction to Operating Systems Fall 2015: Midterm Exam #2 SOLUTIONS

First Midterm Exam September 28, 2017 CS162 Operating Systems

Synchronization 1. Synchronization

Operating Systems (1DT020 & 1TT802)

CS 471 Operating Systems. Yue Cheng. George Mason University Fall 2017

Processes. Process Concept

CPS 310 second midterm exam, 11/14/2014

ii

412-S12 (shankar) Exam 2 SOLUTION Page 1 of 5. 5 problems. 50 points total. Closed book, closed notes, no electronic devices. Write your name above.

EECS 482 Midterm (Fall 1998)

CSE 451: Operating Systems Winter Lecture 7 Synchronization. Hank Levy 412 Sieg Hall

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

CPSC/ECE 3220 Summer 2017 Exam 2

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

Synchronization I. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

TDDB68 Processprogrammering och operativsystem / Concurrent programming and operating systems

CS 537: Introduction to Operating Systems (Summer 2017) University of Wisconsin-Madison Department of Computer Sciences.

CS 61 Section Notes 5

Class average is Undergraduates are performing better. Working with low-level microcontroller timers

COMP 3430 Robert Guderian

Concurrency. On multiprocessors, several threads can execute simultaneously, one on each processor.

CMPSCI 377: Operating Systems Exam 1: Processes, Threads, CPU Scheduling and Synchronization. October 9, 2002

CSC Operating Systems Spring Lecture - XII Midterm Review. Tevfik Ko!ar. Louisiana State University. March 4 th, 2008.

* What are the different states for a task in an OS?

CS-537: Midterm Exam (Spring 2009) The Future of Processors, Operating Systems, and You

CS 318 Principles of Operating Systems

CS 140 Midterm Examination Winter Quarter, 2012

Locks. Dongkun Shin, SKKU

CSC 4320 Test 1 Spring 2017

Midterm I March 11 th, 2015 CS162: Operating Systems and Systems Programming

CS140 Operating Systems and Systems Programming Midterm Exam

CPSC 261 Midterm 2 Thursday March 17 th, 2016

CSE 120 Principles of Operating Systems

Chapter 5: Process Synchronization. Operating System Concepts 9 th Edition

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

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

Synchronization. CS 475, Spring 2018 Concurrent & Distributed Systems

Universidad Carlos III de Madrid Computer Science and Engineering Department Operating Systems Course

CSE 153 Design of Operating Systems

CMSC421: Principles of Operating Systems

Do not start the test until instructed to do so!

Chapter 6 Process Synchronization

Putting it All Together

Transcription:

Times: Thursday 2017-06-22 at 19:00 to 20:50 (7 to 8:50PM) Duration: 1 hour 50 minutes (110 minutes) Exam ID: 3520593 Please print in pen: Waterloo Student ID Number: WatIAM/Quest Login Userid: Sections: CS 350 LEC 001-003 Instructors: Huma Zille Huma, Lesley Ann Istead Examination Midterm Spring 2017 CS 350 Closed Book Candidates may bring no aids (no calculators). University of Waterloo CS350 Midterm Examination Spring 2017 Student Name: Closed Book Exam No Additional Materials Allowed Page 1 of 30

This page intentionally left blank. Page 2 of 30

1. (12 total marks) True or false. If false, justify your answer. a. Each thread has its own address space but can share global variables with other threads. b. A binary semaphore, i.e., a semaphore with one resource, is identical to a lock in every way. c. MIPS instructions ll and sc provide sufficient atomicity to implement a spinlock. d. It is generally better to block than to spin. e. User processes have two address spaces; one for the user data and one for the kernel data. f. While the OS/161 kernel is handling a system call, such as fork, it is possible to be preempted. g. A TLB miss raises an exception which is handled by vm fault. Page 3 of 30

This page intentionally left blank. Page 4 of 30

h. A single level page table must fit into a single page of virtual memory. i. For single and multi-level paging it is most efficient for page size to be equal to frame size. j. The kernel does not distinguish between ready threads and ready processes during scheduling. k. The number of processes that can run concurrently is primarily determined by the amount of physical memory and the virtual memory implementation, not the performance of the CPU. l. The MMU for dynamic relocation must have a relocation and limit register for every process. Page 5 of 30

This page intentionally left blank. Page 6 of 30

2. (11 total marks) Short Answer a. (2 marks) Process A calls fork once producing a single child process, B, with PID 4765. After foking process B, A then calls waitpid on PID 4765, then immediately calls waitpid on 9382. Does the second call to waitpid succeed? Why or why not? b. (2 marks) In the implementation of lock acquire, the wait channel must be locked prior to releasing the spinlock. Why? c. (2 marks) A global shared variable is read, but not written to, by multiple threads. Is a lock required? Why or why not? Page 7 of 30

This page intentionally left blank. Page 8 of 30

d. (5 marks) List the five steps required to implement cv wait. Page 9 of 30

This page intentionally left blank. Page 10 of 30

3. (8 total marks) A user process calls getpid. Before returning from sys getpid there is a timer interrupt that causes a context switch. Draw the user and kernel stacks for the process at this exact time. Page 11 of 30

This page intentionally left blank. Page 12 of 30

4. (8 total marks) Consider function increment max arrays( queue * a, queue * b, queue * c ): void increment max arrays( queue * a, queue * b, queue * c ) { for ( int i = 0; i < a->length(); i ++ ) { if ( a[i] > b[i] && a[i] > c[i] ) a[i] ++; else if ( b[i] > a[i] && b[i] > c[i] ) b[i] ++; else c[i] ++; } } For example, if a = [0,1,2], b = [2,3,1], and c = [8,0,0], then after calling increment max arrays: a = [0,1,3], b = [2,4,1], and c = [9,0,0]. The function increment max arrays can be run concurrently. Suppose there are N queues of equal length and N locks one for each queue. a. (4 marks) Giveapseudocodeimplementationofthesynchronizationrequiredforincrement max arrays using the No Hold and Wait strategy for deadlock prevention. You may assume the lock function bool try acquire( struct lock * lck ) exists. If the lock is available try acquire acquires the lock and returns true. If the lock is not available, the function returns false. Page 13 of 30

This page intentionally left blank. Page 14 of 30

b. (4 marks) Give a pseudocode implementation of the synchronization required for increment max arrays using Resource Ordering. Page 15 of 30

This page intentionally left blank. Page 16 of 30

5. (11 total marks) A system uses 32 bit physical addresses and 24 bit virtual addresses. Frames and pages are 1KB (2 10 bytes). a. (1 mark) What is the maximum amount of addressable physical memory? b. (1 mark) What is the maximum amount of addressable virtual memory? c. (1 mark) How many page table entries (PTEs) are in the page table? d. (1 mark) How many bits are needed for the page number? e. (1 mark) How many bits are needed for the page offset? f. (1 mark) If each PTE is 8 bytes (2 3 ), how big is the page table? Page 17 of 30

This page intentionally left blank. Page 18 of 30

A system uses 32 bit physical addresses and 24 bit virtual addresses. Frames and pages are 1KB (2 10 ). g. (5 marks) A process has a 16KB (2 14 bytes) address space. By coincidence, frame number is equal to page number plus 0x3. i. (1 mark) How many pages are valid in the page table? ii. (1 mark) What is the physical address for virtual address 0xA5A5A5? iii. (1 mark) What is the physical address for virtual address 0x16? iv. (1 mark) What is the virtual address for physical address 0x14A6? v. (1 mark) What is the virtual address for physical address 0x10000000? Page 19 of 30

This page intentionally left blank. Page 20 of 30

6. (8 total marks) Consider the following code: int balance = 0; void Deposit( int value ) { balance += value; } void Withdrawl( int value ) { balance -= value; } void Thread1( void * n, unsigned long tnum ) { for ( int i = 0; i < tnum; i ++ ) { Deposit( tnum ); } } void Thread2( void * n, unsigned long tnum ) { for ( int i = 0; i < tnum; i ++ ) { Withdrawl( i ); } thread fork( "deposit", NULL, Thread1, NULL, 4 ); } int main() { thread fork( "deposit", NULL, Thread1, NULL, 4 ); for ( int i = 0; i < 4; i ++ ) { thread fork( "withdrawl", NULL, Thread2, NULL, 4 ); } } a. (1 mark) What is the total number of threads? b. (1 mark) This code contains a race condition. If balance was volatile would it provide sufficient synchronization to prevent the race condition? Page 21 of 30

This page intentionally left blank. Page 22 of 30

c. (3 marks) Suppose the main thread needs to wait for all other threads to exit before continuing. Describe the changes required to implement this behaviour. d. (3 marks) Which of the following are possible final values for balance? 16 18-16 -18 0 34 Page 23 of 30

This page intentionally left blank. Page 24 of 30

7. (10 total marks) A 32 bit virtual memory implementation combines both paging and segmentation. Each address space is comprised of three segments: code, data and stack. Each segment has its own page table and has a maximum size of 2 20 bytes. The MMU will determine both the segment and page number to perform the translation. a. (1 mark) The highest order bits of the virtual address are reserved for the segment number. How many bits are needed? b. (3 marks) What registers does the MMU need? c. (2 marks) How does the MMU determine if a virtual address is valid? d. (2 marks) What must the kernel do during a process context switch? e. (2 marks) Ifthecodesegmentmustberead-only, whatchangesareneededtosupportthisfeature? Page 25 of 30

This page intentionally left blank. Page 26 of 30

8. (12 total marks) The system call kill is used to terminate a process. kill takes one parameter, the PID of the process to terminate. If no process exists with that number, kill returns an error. a. (5 marks) List the steps required to implement sys kill, including any changes to data structures that might be needed. Page 27 of 30

This page intentionally left blank. Page 28 of 30

In many operating systems you can only kill a process that you created, or, if you have root/admin access. b. (2 marks) What additional data must the kernel store to implement this feature? c. (1 mark) What additional data must the process store to implement this feature? d. (4 marks) List any additional changes to sys kill that may be required to implement this feature. Page 29 of 30

This page intentionally left blank. Page 30 of 30