Midterm Exam #1 September 28, 2016 CS162 Operating Systems

Similar documents
Third Midterm Exam April 24, 2017 CS162 Operating Systems

Third Midterm Exam April 24, 2017 CS162 Operating Systems

Midterm Exam #2 April 20, 2016 CS162 Operating Systems

Midterm Exam #1 February 28, 2018 CS162 Operating Systems

First Midterm Exam September 28, 2017 CS162 Operating Systems

Midterm Exam October 15, 2012 CS162 Operating Systems

Midterm Exam March 13, 2013 CS162 Operating Systems

Midterm Exam #2 Solutions April 20, 2016 CS162 Operating Systems

First Midterm Exam Solutions October 1, 2018 CS162 Operating Systems

Midterm Exam #2 December 4, 2013 CS162 Operating Systems

Midterm Exam March 3, 1999 CS162 Operating Systems

Midterm #2 Exam April 26, 2006 CS162 Operating Systems

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

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

First Midterm Exam September 28, 2017 CS162 Operating Systems

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

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

Final Exam Solutions May 11, 2012 CS162 Operating Systems

Computer Science 162, Fall 2014 David Culler University of California, Berkeley Midterm 1 September 29, 2014

Section 4: Threads CS162. September 15, Warmup Hello World Vocabulary 2

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

Midterm #2 Exam Solutions April 26, 2006 CS162 Operating Systems

Final Exam Solutions May 17, 2013 CS162 Operating Systems

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

Midterm Exam #3 Solutions November 30, 2016 CS162 Operating Systems

Midterm Exam #1 September 29, 1999 CS162 Operating Systems

Section 4: Threads and Context Switching

Midterm I October 12 th, 2005 CS162: Operating Systems and Systems Programming

Midterm Exam #2 April 29, 2003 CS162 Operating Systems

Midterm - Winter SE 350

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

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

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

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

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

Project 2: User Programs

Midterm I October 18 th, 2010 CS162: Operating Systems and Systems Programming

Midterm - Winter SE 350

Processes (Intro) Yannis Smaragdakis, U. Athens

Introduction to OS Processes in Unix, Linux, and Windows MOS 2.1 Mahmoud El-Gayyar

Problem Max Points Score Total 100

Project 2--User Programs

Section 7: Scheduling and Fairness

Computer Science 162, Fall 2014 David Culler University of California, Berkeley Midterm 2 November 14, 2014

CS Operating system

Second Midterm Exam March 21, 2017 CS162 Operating Systems

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

CS 3305 Intro to Threads. Lecture 6

Condition Variables. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Lecture 9: Midterm Review

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

University of Waterloo Midterm Examination Model Solution CS350 Operating Systems

20-EECE-4029 Operating Systems Fall, 2015 John Franco

Computer Systems Assignment 2: Fork and Threads Package

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

Precept 3: Preemptive Scheduler. COS 318: Fall 2018

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

518 Lecture Notes Week 5

Midterm Exam March 7, 2001 CS162 Operating Systems

Midterm I October 19 th, 2009 CS162: Operating Systems and Systems Programming

Midterm I October 15 th, 2008 CS162: Operating Systems and Systems Programming

(In columns, of course.)

CS 318 Principles of Operating Systems

CS333 Intro to Operating Systems. Jonathan Walpole

CSE 451 Midterm Exam May 13 th, 2009

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

There are 12 total numbered pages, 4 Questions. You have 2 hours. Budget your time carefully!

CS 318 Principles of Operating Systems

OS lpr. www. nfsd gcc emacs ls 1/27/09. Process Management. CS 537 Lecture 3: Processes. Example OS in operation. Why Processes? Simplicity + Speed

CS 162 Operating Systems and Systems Programming Professor: Anthony D. Joseph Spring Lecture 8: Semaphores, Monitors, & Condition Variables

cs 140 project 1: threads 9 January 2015

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

TDDB68 Processprogrammering och operativsystem / Concurrent programming and operating systems

TDDB68. Lesson 1. Simon Ståhlberg

518 Lecture Notes Week 3

TDDB Lesson 2 Introduction to Pintos Assignments (1) and 2

CSC 1600 Unix Processes. Goals of This Lecture

CS 153 Design of Operating Systems Winter 2016

NAME: KEY (FIRST NAME FIRST) TOTAL:

CS533 Concepts of Operating Systems. Jonathan Walpole

CS 140 Project 2: User Programs. Fall 2015

4. The Abstraction: The Process

CPS 310 first midterm exam, 2/26/2014

CSC369H1 S2016 Midterm Test Instructor: Bogdan Simion. Duration 50 minutes Aids allowed: none. Student number:

CS-537: Midterm Exam (Spring 2001)

Operating Systems and Networks Assignment 2

CS140 Operating Systems and Systems Programming Midterm Exam

Problem Set 2. CS347: Operating Systems

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

Project 2: User Programs

CS Computer Systems. Project 1: Threads in Pintos

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

CPS 110 Midterm. Out: Wednesday, October 8, 14:50 Due via Hardcopy: 16:05

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

EECS 482 Introduction to Operating Systems

Processes & Threads. Today. Next Time. ! Process concept! Process model! Implementing processes! Multiprocessing once again. ! More of the same J

Processes, Context Switching, and Scheduling. Kevin Webb Swarthmore College January 30, 2018

Lecture 5: Concurrency and Threads

Lecture 4: Mechanism of process execution. Mythili Vutukuru IIT Bombay

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

Transcription:

University of California, Berkeley College of Engineering Computer Science Division EECS Fall 2016 Anthony D. Joseph Midterm Exam #1 September 28, 2016 CS162 Operating Systems Your Name: SID AND 162 Login: TA Name: Discussion Section Time: General Information: This is a closed book and one 2-sided handwritten note examination. You have 80 minutes to answer as many questions as possible. The number in parentheses at the beginning of each question indicates the number of points for that question. You should read all of the questions before starting the exam, as some of the questions are substantially more time consuming. Write all of your answers directly on this paper. Make your answers as concise as possible. If there is something in a question that you believe is open to interpretation, then please ask us about it! Good Luck!! QUESTION POINTS ASSIGNED POINTS OBTAINED 1 21 2 11 3 19 4 22 5 27 TOTAL 100 Page 1/12

1. (21 points total) True/False and Why? a. (8 points) True/False and Why? CIRCLE YOUR ANSWER. i) When a user program performs a system call, it must first put the system call arguments onto the kernel stack and then run a special instruction to switch to kernel mode. TRUE Why? FALSE ii) On a system with a single processor core without hyperthreading, you can speed up a single-threaded program by utilizing multiple threads. TRUE Why? FALSE iii) When a user program successfully calls execv(), its process is replaced with a new program. Everything about the old process is destroyed, including all of the CPU registers, program counter, stack, heap, background threads, file descriptors, and virtual address space. TRUE Why? FALSE Page 2/12

iv) The only way a user thread can transfer control to kernel mode is through syscalls, exceptions, and interrupts. TRUE Why? FALSE b. (13 points) Short answer. i) (4 points) Briefly, in two to three sentences, explain how an Operating System kernel uses dual mode operation to prevent user programs from overwriting kernel data structures. ii) (3 points) Briefly, in two to three sentences, explain the purpose of the while loop in the context of Mesa-style condition variables. Page 3/12

iii) (4 points) Briefly, in two to three sentences, explain the problems with the Therac-25 be specific but brief in your answer. iv) (2 points) In a typical OS, one way that a thread can transition from the running state to the waiting/blocked state is to wait on acquiring a lock. Other than calling sleep or using semaphores or monitors, what are TWO other different types of ways that a thread can transition from the running state to the waiting/blocked state? Page 4/12

2. (11 points total) C Programming. Consider the following C program: int thread_count = 0; void *thread_start(void *arg) { thread_count++; if (thread_count == 3) { char *argv[] = {"/bin/ls", NULL; execv(*argv, argv); printf("thread: %d\n", thread_count); return NULL; int main(int argc, char *argv[]) { int i; for (i = 0; i < 10; i++) { pthread_t *thread = malloc(sizeof(pthread_t)); pthread_create(thread, NULL, &thread_start, NULL); pthread_join(*thread, NULL); return 0; a. (6 points) When you run the program, what will be the output (assume that all system calls succed)? b. (5 points) If we removed the line pthread_join(*thread, NULL), could the output change? If so, explicitly describe the way(s) it might differ. Page 5/12

3. (19 points total) Finite Synchronized Queue using Monitors. In lecture we implemented an Infinite Synchronized Queue using a monitor. In this exam question you will implement a Finite Synchronized Queue (FSQ) using a monitor. The FSQ has Last-In, First-Out semantics (like a stack), a fixed maximum capacity and supports three operations: CreateQueue(), AddToQueue(), and RemoveFromQueue(). a. (6 points) What are the correctness constraints for the Finite Synchronized Queue? 1. 2. 3. Each element of the FSQ is a node: typedef struct { int data; node *next; Node; b. (3 points) Modify the FSQ struct to support a Finite Synchronized Queue. You may assume that you have struct types for the components of a monitor. typedef struct { Node *head; /* pointer to head of queue */ int length; /* number of nodes in queue */ int capacity; /* max size of queue */ FSQ; We have implemented the CreateQueue(int size) function for you. You may assume that the head, length, capacity, and monitor components are initialized. Page 6/12

c. (5 points) Implement the AddToQueue() function. Feel free to use pseudocode for monitor operations. void AddToQueue(FSQ *queue, Node *data) { d. (5 points) Implement the RemoveFromQueue() function. Feel free to use pseudocode for monitor operations. Node *RemoveFromQueue(FSQ *queue) { Page 7/12

4. (22 points total) PintOS questions a. (3 points) What is the maximum number of threads you can create in a user process in PintOS? b. (4 points) How does PintOS preempt the currently running thread in order to schedule a new thread to run, if the currently running thread never yields? c. (3 points) What is the purpose of the idle thread in PintOS? Note that simply saying the idle thread is the thread that runs when the system is idle is not an acceptable answer. d. (4 points) Briefly explain what happens when a timer interrupt occurs while interrupts are disabled in PintOS. Page 8/12

e. (4 points) How does struct thread *switch_threads (struct thread *cur, struct thread *next) work for a thread that has just been created? f. (4 points) Consider the following code for the thread_exit() function in PintOS: void thread_exit (void) { ASSERT (!intr_context ()); #ifdef USERPROG process_exit (); #endif intr_disable (); list_remove (&thread_current()- >allelem); thread_current ()- >status = THREAD_DYING; schedule (); NOT_REACHED (); Briefly explain what NOT_REACHED () means and why this happens. Page 9/12

5. (27 points total) Santa Claus problem (from Operating Systems: Internals and Design Principles) Santa Claus sleeps in his shop and can only be woken up by either: (1) all ten reindeer being back from their vacation or (2) some of the elves having difficulty making toys. The elves can only wake Santa up when 5 of them have a problem. While Santa is helping the 5 elves with their problems, any other elf who needs to meet Santa must wait till the other 5 elves have been tended to first. If Santa wakes up to 5 elves and all ten reindeer, Santa decides that the elves must wait and focuses on getting his sled ready. The last (tenth) reindeer to arrive must get Santa while the others wait before being harnessed to the sled. You can assume that there are only ten reindeer, but you cannot make assumptions on the number of elves. Assume Santa can call these methods: preparesleigh(), helpelves() Reindeer call gethitched() and Elves call gethelp() both gethitched() and gethelp() are thread safe, and can be called outside of critical sections. You MUST implement the problem using semaphores. a. (6 points) What are the correctness constraints? 1. 2. 3. b. (6 points) Initialize the global variables: Page 10/12

c. (5 points) Implement the Santa() function: Santa() { d. (5 points) Implement the ReindeerComesHome() function: ReindeerComesHome() { Page 11/12

e. (5 points) Implement the ElfRequestsHelp() function: ElfRequestsHelp() { Page 12/12