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

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

CSE 4/521 Introduction to Operating Systems

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

CPU Scheduling. Basic Concepts. Histogram of CPU-burst Times. Dispatcher. CPU Scheduler. Alternating Sequence of CPU and I/O Bursts

CSC 716 Advanced Operating System Fall 2007 Exam 1. Answer all the questions. The maximum credit for each question is as shown.

Chapter 6: CPU Scheduling

Scheduling. Today. Next Time Process interaction & communication

Chapter 5 CPU scheduling

Chapter 5: CPU Scheduling. Operating System Concepts 8 th Edition,

Chapter 5: Process Scheduling

CS 322 Operating Systems Practice Midterm Questions

Chapter 5: CPU Scheduling

Chapter 5 Process Scheduling

High Performance Computing Course Notes Shared Memory Parallel Programming

Chapter 5: CPU Scheduling. Operating System Concepts 9 th Edit9on

Process Turnaround Time Total Wait Time P 1 12 ms 0 ms P 2 21 ms 12 ms P 3 23 ms 18 ms P 4 20 ms 17 ms

Job Scheduling. CS170 Fall 2018

CPU Scheduling (Part II)

CS Operating system Fall Midterm I -- Oct 5, 2017 You have 75 min. Good Luck!

Chapter 6: CPU Scheduling. Operating System Concepts 9 th Edition

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

Chapter 6: CPU Scheduling. Operating System Concepts 9 th Edition

Chapter 6: CPU Scheduling

Q1. State True/false with jusification if the answer is false:

4.8 Summary. Practice Exercises

POSIX threads CS 241. February 17, Copyright University of Illinois CS 241 Staff

CS510 Operating System Foundations. Jonathan Walpole

Chapter 5 Scheduling

1.1 CPU I/O Burst Cycle

University of Ottawa School of Information Technology and Engineering

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

CS Operating system Summer Midterm I -- July 11, 2017 You have 115 min (10:00am-11:55pm). Good Luck!

Round Robin (RR) ACSC 271 Operating Systems. RR Example. RR Scheduling. Lecture 9: Scheduling Algorithms

Chapter 6: CPU Scheduling

Processes and Threads

Lecture Contents. 1. Overview. 2. Multithreading Models 3. Examples of Thread Libraries 4. Summary

CS307: Operating Systems

Chapter 5: CPU Scheduling

Chapter 6: CPU Scheduling. Operating System Concepts 9 th Edition

Operating Systems. Engr. Abdul-Rahman Mahmood MS, PMP, MCP, QMR(ISO9001:2000) alphapeeler.sf.net/pubkeys/pkey.htm

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

Chapter 5: CPU Scheduling. Operating System Concepts Essentials 8 th Edition

ECE 7650 Scalable and Secure Internet Services and Architecture ---- A Systems Perspective. Part I: Operating system overview: Processes and threads

CHAPTER 2: PROCESS MANAGEMENT

Multithreaded Programming

Lecture 17: Threads and Scheduling. Thursday, 05 Nov 2009

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

Operating Systems CS 323 Ms. Ines Abbes

CS 370 Operating Systems

CS370 Operating Systems

CPSC 341 OS & Networks. Threads. Dr. Yingwu Zhu

CISC2200 Threads Spring 2015

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

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

Operating Systems and Networks Assignment 2

First Midterm Exam September 28, 2017 CS162 Operating Systems

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

Chapter 5: CPU Scheduling

Definition Multithreading Models Threading Issues Pthreads (Unix)

KEY CENG 334. Midterm. Question 1. Question 2. Question 3. Question 4. Question 5. Question 6. Total. Name, SURNAME and ID

Sample Questions. Amir H. Payberah. Amirkabir University of Technology (Tehran Polytechnic)

Process Concept Process in Memory Process State new running waiting ready terminated Diagram of Process State

Computer Systems Assignment 2: Fork and Threads Package

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

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

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

Chapter 5: Process Scheduling

CS3733: Operating Systems

CS153: Midterm (Winter 19)

Thread. Disclaimer: some slides are adopted from the book authors slides with permission 1

CSCI 4210 Operating Systems CSCI 6140 Computer Operating Systems Sample Midterm Exam Questions (document version 1.1)

SAMPLE MIDTERM QUESTIONS

CS370 Operating Systems

Mon Sep 17, 2007 Lecture 3: Process Management

8: Scheduling. Scheduling. Mark Handley

Threads. Today. Next time. Why threads? Thread model & implementation. CPU Scheduling

Lecture 2 Process Management

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

CS 3305 Intro to Threads. Lecture 6

Scheduling. Today. Next Time. ! Introduction to scheduling! Classical algorithms. ! Process interaction & communication

Threads. To do. Why threads? Thread model & implementation. q q q. q Next time: Synchronization

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

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

EECE.4810/EECE.5730: Operating Systems Spring 2017 Homework 1 Solution Due 3:15 PM, Wednesday, 2/1/17

Processes. Overview. Processes. Process Creation. Process Creation fork() Processes. CPU scheduling. Pål Halvorsen 21/9-2005

COMP 3361: Operating Systems 1 Final Exam Winter 2009

CSMC 412. Operating Systems Prof. Ashok K Agrawala Ashok Agrawala Set 4. September 2006 CMSC 412 Set 4

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

First Midterm Exam Solutions October 1, 2018 CS162 Operating Systems

Processes. CS 475, Spring 2018 Concurrent & Distributed Systems

CSE473/Spring st Midterm Exam Tuesday, February 19, 2007 Professor Trent Jaeger

CMPT 300: Operating Systems I Assignment 1

CS4411 Intro. to Operating Systems Exam 2 Fall 2009

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

Chapter 5: Threads. Single and Multithreaded Processes

Last class: Today: CPU Scheduling. CPU Scheduling Algorithms and Systems

OPERATING SYSTEMS: Lesson 4: Process Scheduling

ALL the assignments (A1, A2, A3) and Projects (P0, P1, P2) we have done so far.

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

Midterm Exam #1 February 28, 2018 CS162 Operating Systems

Transcription:

York University Lassonde School of Engineering Department of Electrical Engineering and Computer Science Midterm EECS 3221.03Z Operating Systems Fundamentals Feb 26, 2015 (14:30-16:00) Section: EECS3221Z Family Name: Given Name: CS Account: Student Id: Solution Instructions 1. The exam has 6 questions and 8 pages (including this one). 2. No aids permitted. 3. Answer each question in the space provided. If you need more space write on the backs of pages. 4. Examination time is 90 minutes. 5. Answers written in pencil or erasable ink will not be considered for remarking. 6. Do not use red ink. Write legibly. Unreadable answers do not count. 7. Generally, no questions re the interpretation, intention, etc. of an exam question will be answered by invigilators. If in doubt, state your interpretation as part of your answer. Question Maximum Mark 1 8 2 8 3 7 4 12 5 8 6 7 Total 50-1 -

1. (8 marks) It is an important job for OS to protect all sorts of resources in a computer system. The basic protection strategy in multiprogramming OS is to use a dual-mode CPU. (a) What are these two CPU modes named? What is the major differences between these two CPU modes? Kernel mode (or system mode or monitor mode) and user mode In kernel mode, CPU can execute all instructions (both normal and previleged instructions) In user mode, CPU can execute only normal instructions and CPU will generate an error if it is foreced to execute a previleged instruction in user mode) (2 marks) (b) Explain why OS needs such a dual-mode mechanism for effective hardware protection. The same CPU sometimes needs to run OS code to manage computer resources (CPU needs super-power in this case). The same CPU sometimes needs to run user programs (CPU power must be limited in order to protect any user program from damaging the system). (2 marks) (c) How do OS and CPU hardware together guarantee a correct logic in implementing dualmode operation? To guarantee that whenever CPU runs OS code, it is in kernel mode; whenever CPU runs user code, it is in user mode. Consider three cases: i) After system rebooting, CPU in kernel mode and OS takes control of CPU. ii) OS needs to explicitly switch CPU to user mode before it passes CPU to any user program. iii) When an interrupt happens, hardware forces CPU to run interrupt handler program (part of OS kernel) and meanwhile it forces CPU switch to kernel model. (4 marks) - 2 -

2. (8 marks) You are given a three-state process model as follows. WAITING 1. For each of the following transitions, answer whether it is allowed or not (circle one). If allowed, show an event that triggers such a transition; if not allowed, briefly explain why in 1-2 sentences. Marking scheme: 2 marks each; correct choice 1 mark; good explanation 1 more mark (1) RUNNING READY [ Allowed X Not Allowed ] time slice expires may cause this; or another more important process becomes ready (2) WAITING RUNNING [ Allowed Not Allowed X ] all waiting processes will first go to ready first; it needs CPU scheduler to decide who goes from ready to running. (3) READY WAITING [ Allowed Not Allowed X ] a process can t become waiting from ready to run without running in CPU (4) RUNNING WAITING [ Allowed X Not Allowed ] the running process make an IO requestion; or IO-reated system calls - 3 -

3. (7 marks) Briefly answer the following questions about system calls in OS. (1) (1 mark) What system calls are used for in OS? system calls are used for OS to provide services to other applications or programs; OR normal program can make system calls to request OS services (2) (2 marks) What differences are between system calls and function calls? function calls are used for requesting services in the same space (either user or kernel) system calls are used for requesting services in kernel space from user space; it crosses the space boundary so that it needs to switch CPU mode (user kenerl) at the same time (3) Briefly expalin how sytem calls are implemented in OS? Consider its implementation in both user space and kernel space. a. (2 marks) In User Space: i) save system call number and all parameters ii) execute software interrupt instruction (TRAP) b. (2 marks) In Kernel Space: i) All system calls are implemented in the interrupt handler program correponding to TRAP ii) where jump to dfferent parts based on the saved system call number; after it is done, switch back to user mode and return to user program - 4 -

4. (12 marks) Assume the following programs runs normally in Unix. 4.1) (6 marks) Program A: #include <stdio.h> int num = 0 ; int main(int argc, char *argv[]) { int pid1=0, pid2=0, pid3=0; pid1 = fork() ; pid2 = fork() ; if(pid1 == 0 ) { else { printf( A\n ) ; pid3 = fork() ; printf( B\n ) ; if (pid2!= 0 && pid3!= 0) { printf( C\n ) ; What is the total number of processes that will be created by runnng this program? How many of each character A to C will be printed out? Briefly explain why. 2 A s 4 B s 1 C (2 marks) 6 processes (inclduing the original one) (2 marks) Need a brief explanation about the following hierarchical structure (2 marks) - 5 -

Midterm EECS 3221Z, Winter 2015 4.2) (6 marks) Program B: #include <pthread.h> #include <stdio.h> int value = 0 ; void *runner(void *param) { value = 5 ; pthread_exit(0) ; int main( int argc, char *argv[]) { int pid; pthread_t tid ; pthread_attr_t attr ; pid = fork() ; if (pid == 0) { pthread_attr_init(&attr) ; -6- Feb 26, 2015

pthread_create(&tid, &attr, runner, NULL) ; pthread_join(tid,null) ; printf( value = %d\n, value) ; else if (pid > 0) { value = 10 ; wait(null) ; printf( value = %d\n, value) ; Please describe all possible outputs for the following two programs and explain how each output happens. Correct output: value = 5 value = 10 Explanation: *) fork() creates two processes and gets two copies of value; *) Child process create a new thread -> two threads in child process and both threads share one copy of value in child process. The new thread change it from 0 to 5 ; the other thread wait and then print its value as value=5. *) Parent process changes its own copy of value from 0 to 10 and wait and then print its value as value=10 *) since parent wait(null), the child process always print before parent process. - 7 -

5. (8 marks) Here is a table of processes and their arrival times and CPU burst lengths: Process ID Arrival Time CPU burst P1 0 4 P2 2 6 P3 3 2 P4 7 4 Assume there is one CPU available, show the scheduling order for these processes under FCFS, preemptive Shortest-Job First (SJF), and Round-Robin (RR) (quantum=1 time unit). Fill the table to show which process CPU is running at each time. Assume that context switch overhead is 0. In RR, assume new arrival process is given priority over time-quantum-expired process. Time FCFS SJF RR 0 P1 P1 P1 1 P1 P1 P1 2 P1 P1 P2 3 P1 P1 P1 4 P2 P3 P3 5 P2 P3 P2 6 P2 P2 P1 7 P2 P4 P3 8 P2 P4 P2 9 P2 P4 P4 10 P3 P4 P2 11 P3 P2 P4 12 P4 P2 P2 13 P4 P2 P4 14 P4 P2 P2 15 P4 P2 P4 Calculate the waiting time for these three scheduling algorithms: FCSF: 14 SJF: 9 RR: 18-8 -

6. (7 marks) The following method is proposed to keep track of how many child threads are currently active in a multi-threaded program. /*1*/ int NumThreads = 0; /*2*/ void *runner() /*3*/ { /*4*/ NumThreads++; /* child thread does its work here */ /*5*/ NumThreads--; /*6*/ return ; /*7*/ /*8*/ int main(int argc, char *argv[]) /*9*/ { /*10*/ pthread_t tid1[maxsize]; /* the thread identifiers */ /*11*/ for(i=0; i<maxsize; i++) { /*12*/ pthread_create(&tid[i],null,runner,null); /*13*/ /*14*/ printf( Currently %d threads are working\n, NumThreads); /*17*/ Explain whether line 14 always prints out the correct number of active threads that are currently running between lines 4 and 5 (not including lines 4 and 5). Please answer YES or NO first and then justify your answer. (answer Yes 0 mark; answer No but without justification, 2 marks maximum) NO, it can t always print a correct value because of race condition. Multiple threads are modifying the same variable NumThreads at the same time without any protection. Context switch may cause execution sequences of these threads interleaving so that the resultant value becomes unexpected. Need to use line 4 and line 5 to explain how the execution sequences are actually interleaved. - 9 -