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

Similar documents
CSCI 4210 Operating Systems CSCI 6140 Computer Operating Systems Sample Exam 1 Questions (document version 1.1)

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

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

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

University of Ottawa School of Information Technology and Engineering

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

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

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

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

CS 322 Operating Systems Practice Midterm Questions

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

CSCI 4210 Operating Systems CSCI 6140 Computer Operating Systems Sample Exam 2 Questions (document version 1.0)

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

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

EECE.4810/EECE.5730: Operating Systems Spring 2017 Homework 3 Solution

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

CHAPTER 2: PROCESS MANAGEMENT

CS Mid term Exam Maximum points 100; Maximum time allowed: 75 minutes

CS630 Operating System Design, First Exam, Spring 2017,

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

CSCI 4210 Operating Systems CSCI 6140 Computer Operating Systems Project 1 (document version 1.3) Process Simulation Framework

Maria Hybinette, UGA. ! One easy way to communicate is to use files. ! File descriptors. 3 Maria Hybinette, UGA. ! Simple example: who sort

Reminder. Exam QuesVon 1a. 1 st Midterm Exam Thursday February 18, 9.30am, in class Keep seat open between you and neighbor!

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

Chapter 5: CPU Scheduling

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

1.1 CPU I/O Burst Cycle

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

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

CSE 4/521 Introduction to Operating Systems

CPU Scheduling Algorithms

Operating Systems. Lecture 05

SAMPLE MIDTERM QUESTIONS

CS 3733 Operating Systems

IC221: Systems Programming 12-Week Written Exam [SOLUTIONS]

Operating Systems and Networks Assignment 2

Operating systems Portfolio

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

INF1060: Introduction to Operating Systems and Data Communication. Pål Halvorsen. Wednesday, September 29, 2010

Figure 1 Ring Structures

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

Lecture 2 Process Management

TCSS 422: OPERATING SYSTEMS

OPERATING SYSTEMS CS3502 Spring Processor Scheduling. Chapter 5

CS240: Programming in C

CSci 4061 Introduction to Operating Systems. IPC: Basics, Pipes

CS3733: Operating Systems

CSci 4061 Introduction to Operating Systems. IPC: Basics, Pipes

CSci 4061 Introduction to Operating Systems. IPC: Basics, Pipes

Operating Systems. Figure: Process States. 1 P a g e

Week 2 Intro to the Shell with Fork, Exec, Wait. Sarah Diesburg Operating Systems CS 3430

What Is A Process? Process States. Process Concept. Process Control Block (PCB) Process State Transition Diagram 9/6/2013. Process Fundamentals

Chapter 3 Processes we will completely ignore threads today

Introduction to Processes

CMPT 300: Operating Systems I Assignment 1

Preview. Process Scheduler. Process Scheduling Algorithms for Batch System. Process Scheduling Algorithms for Interactive System

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Information Sciences and Engineering

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

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

3. CPU Scheduling. Operating System Concepts with Java 8th Edition Silberschatz, Galvin and Gagn

Chapter 6: CPU Scheduling

CS 370 Operating Systems

Properties of Processes

CSSE 332 OPERATING SYSTEMS

Preview. Process Control. What is process? Process identifier The fork() System Call File Sharing Race Condition. COSC350 System Software, Fall

Scheduling of processes

Announcement (1) sys.skku.edu is now available

COE518 Lecture Notes Week 4 (Sept. 26, 2011)

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

8: Scheduling. Scheduling. Mark Handley

The Process Abstraction. CMPU 334 Operating Systems Jason Waterman

CSE 410: Systems Programming

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

First Midterm Exam Solutions October 1, 2018 CS162 Operating Systems

First Midterm Exam September 28, 2017 CS162 Operating Systems

CSC 1600 Unix Processes. Goals of This Lecture

Processes. CS 475, Spring 2018 Concurrent & Distributed Systems

CS 261 Fall Mike Lam, Professor. Processes

Programming Assignment HW5: CPU Scheduling draft v04/02/18 4 PM Deadline April 7th, 2018, 5 PM. Late deadline with penalty April 9th, 2018, 5 PM

Fall 2015 COMP Operating Systems. Lab #3

Processes COMPSCI 386

Q 1. (10 Points) Assume that a process executes the following pseudo codes:

King Saud University. College of Computer & Information Sciences. Information Technology Department. IT425: Operating Systems.

Notice: This set of slides is based on the notes by Professor Perrone of Bucknell and the textbook authors Silberschatz, Galvin, and Gagne

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

Computer Systems Assignment 2: Fork and Threads Package

518 Lecture Notes Week 3

COSC243 Part 2: Operating Systems

Process a program in execution; process execution must progress in sequential fashion. Operating Systems

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

CS 537: Intro to Operating Systems (Fall 2017) Worksheet 3 - Scheduling & Process API Due: Sep 27 th 2017 (Wed) in-class OR Simmi before 5:30 pm

Chapter 6: CPU Scheduling

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

Operating System Concepts Ch. 5: Scheduling

Interacting with Unix

CS370 Operating Systems

Operating Systems Lab

What is a Process. Preview. What is a Process. What is a Process. Process Instruction Cycle. Process Instruction Cycle 3/14/2018.

Operating Systems (1DT020 & 1TT802)

Ricardo Rocha. Department of Computer Science Faculty of Sciences University of Porto

Transcription:

Name: SOLUTIONS Score: / 100 CSCI-4210/6140 Operating Systems Midterm Exam Thursday 10/9 1-PAGE (2-SIDED) CRIB SHEET ALLOWED; NO CALCULATOR ANSWER ALL QUESTIONS; USE EXTRA PAPER AS NECESSARY 1. [25 POINTS] For parts (a) through (d) below, calculate the individual turnaround times and total wait times for processes P 1, P 2, P 3, and P 4 as described in the following table: Process Arrival time CPU burst time P 1 0 ms 12 ms P 2 0 ms 9 ms P 3 3 ms 5 ms P 4 9 ms 3 ms [0.5pts for each answer in the tables; including "ms" is not required] a. [4 points] Apply the First-Come First-Served (FCFS) scheduling algorithm. 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 b. [6 points] Apply the Shortest Remaining Time (SRT) scheduling algorithm, i.e. a preemptive version of the Shortest Job First (SJF) algorithm. Also calculate the number of preemptions each process experiences. Process Turnaround Time Total Wait Time Preemptions P 1 29 ms 17 ms 0 P 2 17 ms 8 ms 2 P 3 5 ms 0 ms 0 P 4 3 ms 0 ms 0 1

c. [6 points] Apply the Round Robin (RR) scheduling algorithm with a time slice (i.e. quantum) of 2 milliseconds. Also calculate the number of preemptions each process experiences. Process Turnaround Time Total Wait Time Preemptions P 1 29 ms 17 ms 5 P 2 27 ms 18 ms 4 P 3 18 ms 13 ms 2 P 4 13 ms 10 ms 1 d. [6 points] Apply the Round Robin (RR) scheduling algorithm with a time slice (i.e. quantum) of 4 milliseconds. Also calculate the number of preemptions each process experiences. Process Turnaround Time Total Wait Time Preemptions P 1 28 ms 16 ms 2 P 2 29 ms 20 ms 2 P 3 21 ms 16 ms 1 P 4 14 ms 11 ms 0 e. [3 points] Increasing the time slice from 4 ms, at what point (i.e. what time slice value) does the RR algorithm degenerate into the FCFS algorithm? 12 ms (largest CPU burst time) 2

2. [25 POINTS] Given the following C program, answer the questions presented below. Assume that all system calls complete successfully. Further, assume that the parent process ID is 64, with any child processes numbered 128, 129, 130, etc. #include <stdio.h> #include <stdlib.h> #include <unistd.h> int main() pid_t pid; pid_t * x = (pid_t *)malloc( sizeof( pid_t ) ); printf( "PARENT: %d\n", getpid() ); pid = fork(); printf( "PARENT: %d\n", pid ); *x = pid * 10; if ( pid == 0 ) printf( "CHILD:!\n" ); *x *= 5; printf( "CHILD: %d\n", *x ); else if ( pid > 0 ) printf( "PARENT: %d\n", *x ); *x -= 10; printf( "PARENT: (-: %d\n", *x ); free( x ); return 0; a. [17 points] Write the exact terminal output in the space below. If multiple outputs are possible, please succinctly describe all possibilities by using a diagram. [1pt] PARENT: 64 PARENT outputs: [2pts] PARENT: 128 [2pts] PARENT: 1280 [2pts] PARENT: (-: 1270 [2pts] these PARENT and CHILD output lines are interleaved CHILD outputs: [2pts] the order of output lines [ ] PARENT: 0 in PARENT and CHILD must [2pts] CHILD:! each be in relative orders [2pts] CHILD: 0 shown [2pts] PARENT: (-: -10 3

b. [8 points] If the processes in the code on the previous page were dispatched using the First-Come First-Served (FCFS) scheduling algorithm, write the exact terminal output in the space below. If multiple outputs are possible, please succinctly describe all possibilities by using a diagram. [2pts] PARENT: 64 [1pt] PARENT: 128 [1pt] PARENT: 1280 [1pt] PARENT: (-: 1270 [ ] CHILD: 0 [1pt] CHILD:! [1pt] CHILD: 0 [1pt] PARENT: (-: -10 (i.e. no interleaving, because PARENT runs without interruption) 4

3. [25 POINTS] Given the following C program, answer the questions presented below. Assume that all system calls complete successfully. Further, assume that the parent process ID is 128, with any child processes numbered 256, 257, 258, etc. #include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <fcntl.h> #include <sys/wait.h> int main() close( 1 ); int rc = open( "j.txt", O_WRONLY O_CREAT O_TRUNC ); pid_t pid = fork(); printf( "[? %d]", pid ); if ( pid == 0 ) fprintf( stderr, "[?!]" ); rc = dup2( 1, 2 ); fprintf( stderr, "[&& %d]", rc ); else if ( pid > 0 ) wait( NULL ); fprintf( stderr, "[$$ %d]", pid ); return EXIT_SUCCESS; a. [9 points] Write the exact terminal output in the space below. If multiple outputs are possible, please succinctly describe all possibilities by using a diagram. 3pts vvvv [?!][$$ 256] ^^^^ ^^^^ 3pts 3pts 5

b. [9 points] Write the exact contents of the j.txt file below. If multiple outputs are possible, please succinctly describe all possibilities by using a diagram. 3pts vvvvv [&& 2][? 0][? 256] ^^^^^^ ^^^^^^^ 3pts 3pts (last two segments appear in either order) c. [7 points] If the wait() system call is omitted from the code on the previous page, write the exact terminal output in the space below. If multiple outputs are possible, please succinctly describe all possibilities by using a diagram. 3pts vvvv [$$ 256][?!] ^^^^ ^^^^ 2pts 2pts (segments appear in either order) 6

4. [25 POINTS] Given the following C program, answer questions (a) and (b) below. Assume that all system calls complete successfully. Further, assume that the parent process ID is 256, with any child processes numbered 512, 513, 514, etc. #include <stdio.h> #include <stdlib.h> #include <unistd.h> int main() int p[2]; int rc = pipe( p ); printf( "%d-%d-%d\n", getpid(), p[0], p[1] ); rc = fork(); if ( rc == 0 ) rc = write( p[1], "DOIREALLYLOOKLIKEAGUYWITHAPLAN?", 31 ); if ( rc > 0 ) int n = p[0] * p[0] - p[1]; char * buffer = (char *)calloc( n + 1, sizeof( char ) ); rc = read( p[0], buffer, n ); printf( "%d-%s\n", getpid(), buffer ); free( buffer ); return EXIT_SUCCESS; a. [9 points] Write the exact terminal output in the space below. If multiple outputs are possible, please succinctly describe all possibilities by using a diagram. [3pts] 256-3-4 PARENT: [2pts] 256-DOIRE CHILD: [2pts] 512-ALLYL [1pt] [1pt] PARENT and CHILD lines could be interleaved (swapped) PARENT could be ALLYL instead of DOIRE and likewise for CHILD b. [4 points] Why is the first argument of the calloc() call n + 1 (instead of just n)? [4pts] Extra byte is for the '\0' character (NULL or EOS terminator) 7

c. [12 points] Given the following C program, write the exact terminal output in the space below. As per usual, if multiple outputs are possible, please describe all possibilities by using a diagram. Assume that all system calls complete successfully. Further, assume that the parent process ID is 512, with any child processes numbered 1024, 1025, 1026 etc. #include <stdio.h> #include <stdlib.h> #include <unistd.h> int main() char b[20]; int p[2]; int rc = pipe( p ); int pid = fork(); if ( pid > 0 ) close( p[0] ); rc = dup2( p[1], 1 ); printf( "0987654321" ); fflush( NULL ); if ( pid == 0 ) close( p[1] ); rc = read( p[0], b, 6 ); b[rc] = '\0'; printf( "%d-%s\n", getpid(), b ); return EXIT_SUCCESS; 4pts vvvvv 09876543211024-098765 ^^^^^^^^^^ ^^^^^^ 4pts 4pts 8

USE THIS PAGE FOR ADDITIONAL WORK, IF NECESSARY (ALSO SEE EXTRA CREDIT QUESTIONS BELOW) 5. [EXTRA CREDIT +1] In what year did Dr. Goldschmidt s favorite breakfast cereal s mascot first appear on cereal boxes? [+1pt] 1965 6. [EXTRA CREDIT +1] What infamous villain hangs from Dr. Goldschmidt s keychain (with feet that light up)? [+1pt] The Joker all done 9