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

Similar documents
Arvind Krishnamurthy Spring Threads, synchronization, scheduling Virtual memory File systems Networking

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

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

CS-537: Midterm Exam (Spring 2001)

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

Lecture Topics. Announcements. Today: Threads (Stallings, chapter , 4.6) Next: Concurrency (Stallings, chapter , 5.

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

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

High Performance Computing Course Notes Shared Memory Parallel Programming

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

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

Processes. Operating System CS 217. Supports virtual machines. Provides services: User Process. User Process. OS Kernel. Hardware

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

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

CSC 4320 Test 1 Spring 2017

Processes. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Processes. OS Structure. OS Structure. Modes of Execution. Typical Functions of an OS Kernel. Non-Kernel OS. COMP755 Advanced Operating Systems

CS5460: Operating Systems

Threads. What is a thread? Motivation. Single and Multithreaded Processes. Benefits

Processes. Johan Montelius KTH

CS 3305 Intro to Threads. Lecture 6

A process. the stack

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 333 Introduction to Operating Systems. Class 3 Threads & Concurrency. Jonathan Walpole Computer Science Portland State University

CS153: Midterm (Winter 19)

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

CS510 Operating System Foundations. Jonathan Walpole

Processes. CS3026 Operating Systems Lecture 05

CSE 120 Principles of Operating Systems

CS 318 Principles of Operating Systems

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

University of Waterloo Midterm Examination Term: Winter Year: 2013

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

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING UNIT I

Processes. CS 475, Spring 2018 Concurrent & Distributed Systems

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

Lecture 9: Midterm Review

Windows architecture. user. mode. Env. subsystems. Executive. Device drivers Kernel. kernel. mode HAL. Hardware. Process B. Process C.

Altering the Control Flow

SE350: Operating Systems. Lecture 3: Concurrency

( D ) 4. Which is not able to solve the race condition? (A) Test and Set Lock (B) Semaphore (C) Monitor (D) Shared memory

COMP 3100 Operating Systems

Concurrency, Thread. Dongkun Shin, SKKU

Lecture 5: Synchronization w/locks

Lecture 4: Memory Management & The Programming Interface

EECS 482 Introduction to Operating Systems

Midterm Exam October 15, 2012 CS162 Operating Systems

Exam Guide COMPSCI 386

CS 33. Architecture and the OS. CS33 Intro to Computer Systems XIX 1 Copyright 2017 Thomas W. Doeppner. All rights reserved.

Fall 2015 COMP Operating Systems. Lab #3

LSN 13 Linux Concurrency Mechanisms

Midterm Exam March 3, 1999 CS162 Operating Systems

Lecture 4: Threads; weaving control flow

CSCI 4210 Operating Systems CSCI 6140 Computer Operating Systems Sample Final Exam Questions (document version 1.1) WITH SELECTED SOLUTIONS

CS 5523: Operating Systems

www nfsd emacs lpr Process Management CS 537 Lecture 4: Processes Example OS in operation Why Processes? Simplicity + Speed

University of Waterloo CS350 Midterm Examination Model Solution

Operating Systems Design Fall 2010 Exam 1 Review. Paul Krzyzanowski

a) Do exercise (5th Edition Patterson & Hennessy). Note: Branches are calculated in the execution stage.

Administrivia. Nachos guide and Lab #1 are on the web.

CS 261 Fall Mike Lam, Professor. Threads

CS 33. Architecture and the OS. CS33 Intro to Computer Systems XIX 1 Copyright 2018 Thomas W. Doeppner. All rights reserved.

Announcement. Exercise #2 will be out today. Due date is next Monday

Precept 2: Non-preemptive Scheduler. COS 318: Fall 2018

518 Lecture Notes Week 3

pthreads CS449 Fall 2017

Operating System. Chapter 3. Process. Lynn Choi School of Electrical Engineering

CS Operating system

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

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

CSE 120 Principles of Operating Systems

Lecture Topics. Announcements. Today: Concurrency: Mutual Exclusion (Stallings, chapter , 5.7)

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

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

What is an Operating System?

CSE 120 Principles of Operating Systems

CS 350 Operating Systems Course Notes

Lecture 5: Concurrency and Threads

OS Structure. User mode/ kernel mode. System call. Other concepts to know. Memory protection, privileged instructions

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

PROCESSES. Jo, Heeseung

Processes. Jo, Heeseung

Threads and Concurrency

First Midterm Exam Solutions October 1, 2018 CS162 Operating Systems

EECS 3221 Operating System Fundamentals

EECS 3221 Operating System Fundamentals

PROCESS MANAGEMENT. Operating Systems 2015 Spring by Euiseong Seo

1.2 We have stressed the need for an operating system to make efficient use. of the computing hardware. When is it appropriate for the operating

System Call. Preview. System Call. System Call. System Call 9/7/2018

Altering the Control Flow

CS 326: Operating Systems. Process Execution. Lecture 5

CSCE 313 Introduction to Computer Systems. Instructor: Dezhen Song

Parallel Programming Languages COMP360

Operating System Structure

Memory Management - Demand Paging and Multi-level Page Tables

CSCE 313: Intro to Computer Systems

Computer Systems II. First Two Major Computer System Evolution Steps

Exceptional Control Flow Part I Oct. 17, 2002

Processes. CS 416: Operating Systems Design, Spring 2011 Department of Computer Science Rutgers University

OS lpr. www. nfsd gcc emacs ls 9/18/11. Process Management. CS 537 Lecture 4: Processes. The Process. Why Processes? Simplicity + Speed

Transcription:

Spring 2015. CS 170 Exercise Set 1 (Updated with Part III) Due on May 5 Tuesday 12:30pm. Submit to the CS170 homework box or bring to the classroom. Additional problems will be added as we cover more topics before midterm. Part I. Introduction. Processes/Threads 1. What are typical services provided by OS? 2. Which of the following instructions should be privileged? a. Set value of timer. b. Read the clock. c. Issue a trap instruction. d. Turn off interrupts. e. Access I/O device. 3. What is the purpose of system calls? 4. When a process creates a new process using the fork() operation, which of the following state is shared between the parent process and the child process? a. Stack b. Heap c. Shared memory segments d. Code 5. Provide two programming examples in which multithreading provides better performance than a single-threaded solution. 6. What are main differences between user-level threads and kernel-level threads?

7. Describe the actions taken to context-switch threads. 8. Answer the following question to trace a program without actually running in a machine. void main() { char *cmd[]={ echo, hello,0; int pid, x=10, y; pid = fork(); if (pid == 0) { y=1; x=x+y; printf("x is %d. y is %d \n", x,y); execvp(cmd[0],cmd); printf("x is %d. y is %d \n", x,y); else { y=2; x=x+y; wait (NULL); printf("x is %d. y is %d \n", x,y); Given the above c program that uses system calls, show all possible traces (what can be printed on the screen) when running a multiprogramming Linux system. Provide an explanation. 9. What is the possible output of running this nachos program ThreadTest()? Provide an explanation. You need to give a solution without actually running in a CSIL machine. int x=10; void SimpleThread(int y) { printf(" Before yield, Thread %d: x is %d.\n", y, x); currentthread->yield(); x=x+y;

printf(" After yield, Thread %d: x is %d. \n", y, x); void ThreadTest() { Thread *t = new Thread("forked thread"); t->fork(simplethread, 1); SimpleThread(2); 10. Explain what Nachos OS does in each of the following four statements when spawning Nachos threads: Thread::Fork(VoidFunctionPtr func, int arg) { StackAllocate(func, arg); IntStatus oldlevel = interrupt->setlevel(intoff); scheduler->readytorun(this); (void) interrupt->setlevel(oldlevel); Part II. Synchronization 1. What is a race condition? 2. What is the difference between deadlock and starvation? 3. The following program manages a set of free memory blocks used by multiple threads. Each thread calls allocate() to get a free block to use and calls free() to release a specific block so others can use. The program maintains an

array available[nb] whose elements are non-zero if the corresponding blocks are available (NB is a constant indicating the total memory blocks available initially). int available[nb]; int allocate() { /* Returns index of available free blocks. */ int i; while(1) { for (i=0; i < NB; i++) if (available [i]!= 0 { available[i] = 0; return i; free(int i) { /* Release block i */ available[i] = 1; Modify the above code using 1) locks and condition variables so that the multiple threads are well symphonized in accessing the critical section and busy waiting is minimized. 2) using semaphores only. 4. Explain the purpose of each line in the following Nachos source code for implementing the semaphore primitive.

Part III. Memory Management 1. List the key steps that are necessary to run a program on a completely dedicated machine. 2. What are differences between logical and physical addresses? 3. Consider a logical address space of 64 pages of 1KB each, mapped onto a physical memory of 32 pages. a. How many bits are there in the logical address? b. How many bits are there in the physical address?

4. Given a one-level paging scheme for memory address mapping, if TLB access takes 10 nanosecond and each physical memory access takes 100 nanoseconds, what will be the desired TLB hit ratio to have the effective memory access time within 120 nanoseconds to complete both logical address translation and physical memory data fetching? 5. Given a one-level paging scheme where physical memory is divided into a set of pages with uniform size 8K bytes and each page table entry uses 4 bytes, what is the maximum size of a logical memory space for each process with this paging scheme? Explain your reason. 6. Design a 2-level paging scheme for a 38-bit logical space and illustrate the address translation steps. Each physical page is of size 16K bytes and each page table entry uses 4 bytes. Each 38-bit logical address is translated into a 38-bit physical address. 7. The following C program access a C array with a million of integer elements, running on a Linux CSIL machine. How does increasing of the page size affect the TLB miss ratio? Explain the reason. int i, sum=0; For(i=0; i<1000000; i++) sum += a[i];