CS 322 Operating Systems Practice Midterm Questions

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

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

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

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

Processes. CS 475, Spring 2018 Concurrent & Distributed Systems

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

CHAPTER 2: PROCESS MANAGEMENT

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

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

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

Lecture Topics. Announcements. Today: Uniprocessor Scheduling (Stallings, chapter ) Next: Advanced Scheduling (Stallings, chapter

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

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

CS3733: Operating Systems

Memory Management. 3. What two registers can be used to provide a simple form of memory protection? Base register Limit Register

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

Processes. Process Management Chapter 3. When does a process gets created? When does a process gets terminated?

Chapter 5: CPU Scheduling

CS 3733 Operating Systems

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

CS 31: Intro to Systems Processes. Kevin Webb Swarthmore College March 31, 2016

Lecture 4: Memory Management & The Programming Interface

Lecture 2 Process Management

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

Process Concepts 8/21/2014. CS341: Operating System. Scheduling: Theoretical Analysis

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

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

Mon Sep 17, 2007 Lecture 3: Process Management

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

Linux Operating System

Problem Set: Processes

CS370 Operating Systems

Memory management. Requirements. Relocation: program loading. Terms. Relocation. Protection. Sharing. Logical organization. Physical organization

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

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

by Marina Cholakyan, Hyduke Noshadi, Sepehr Sahba and Young Cha

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

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

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

CS 370 Operating Systems

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

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

Operating Systems and Networks Assignment 2

Threads and Too Much Milk! CS439: Principles of Computer Systems February 6, 2019

May 19, Answer pieces in italics were not required to receive full points.

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

Process! Process Creation / Termination! Process Transitions in" the Two-State Process Model! A Two-State Process Model!

Processes. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

SMD149 - Operating Systems

CS 326: Operating Systems. CPU Scheduling. Lecture 6

OPERATING SYSTEMS CS3502 Spring Processor Scheduling. Chapter 5

Computer Systems II. First Two Major Computer System Evolution Steps

Operating System Concepts Ch. 5: Scheduling

THE PROCESS ABSTRACTION. CS124 Operating Systems Winter , Lecture 7

Problem Set: Processes

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

Operating Systems Design Fall 2010 Exam 1 Review. Paul Krzyzanowski

Threads and Too Much Milk! CS439: Principles of Computer Systems January 31, 2018

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

Processes. Operating System Concepts 8 th Edition

Operating Systems (1DT020 & 1TT802)

Announcements/Reminders

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

Properties of Processes

Processes and Threads

Computer Systems Assignment 2: Fork and Threads Package

CS2506 Quick Revision

Exam Guide COMPSCI 386

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

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

csci3411: Operating Systems

Operating Systems. Instructor: Dmitri A. Gusev. Spring Lecture 16, April 17, CSC : Introduction to Computer Science

For The following Exercises, mark the answers True and False

Prepared by Prof. Hui Jiang Process. Prof. Hui Jiang Dept of Electrical Engineering and Computer Science, York University

The Process Abstraction. CMPU 334 Operating Systems Jason Waterman

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

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 26

Process. Prepared by Prof. Hui Jiang Dept. of EECS, York Univ. 1. Process in Memory (I) PROCESS. Process. How OS manages CPU usage? No.

Operating Systems CMPSC 473. Process Management January 29, Lecture 4 Instructor: Trent Jaeger

CS 241 Data Organization Binary Trees

Processes. Dr. Yingwu Zhu

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

Chapter 6: CPU Scheduling

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

Addresses in the source program are generally symbolic. A compiler will typically bind these symbolic addresses to re-locatable addresses.

CS 537 Lecture 2 - Processes

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

518 Lecture Notes Week 3

CS 31: Intro to Systems Operating Systems Overview. Kevin Webb Swarthmore College March 31, 2015

8: Scheduling. Scheduling. Mark Handley

Scheduling. Scheduling. Scheduling. Scheduling Criteria. Priorities. Scheduling

CSE 4/521 Introduction to Operating Systems

Process. Heechul Yun. Disclaimer: some slides are adopted from the book authors slides with permission 1

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

Process. Heechul Yun. Disclaimer: some slides are adopted from the book authors slides with permission

CS 550 Operating Systems Spring Process II

Introduction to Operating Systems Prof. Chester Rebeiro Department of Computer Science and Engineering Indian Institute of Technology, Madras

CSE 120 Principles of Operating Systems Spring 2017

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

The Kernel Abstraction. Chapter 2 OSPP Part I

Transcription:

! CS 322 Operating Systems 1. Processes go through the following states in their lifetime. time slice ends Consider the following events and answer the questions that follow. Assume there are 5 processes, all either in the read or running states initially. Assume the processes are using a single processor. At time 5: P1 executes a command to read from disk 3. At time 15: P3 s time slice ends. At time 18: P4 executes a command to write to disk 3. At time 20: P2 executes a command to read from disk 2. At time 24: P3 executes a command to join with P5. At time 33: An interrupt occurs indicating that P2 s read is complete. At time 36: An interrupt occurs indicating that P1 s read is complete. At time 38: P5 terminates. At time 48: An interrupt occurs indicating that P4 s write is complete. For each time 22, 37 and 47, identify which state each process is in. If it is waiting, indicate what it is waiting for. T22: waiting on disk 2: P2; waiting on disk 3: P1, P4; ready/runnning: P5, P3 T37: waiting for P5 to finish: P3; waiting on disk 3: P4; ready/running: P1, P2, P5 T47: finished: P5; waiting on disk 3: P4; ready/running: P1, P2, P3 2. An operating system s services can be described in terms of a mechanism that enables the service and a policy that determines how the service gets used. Briefly describe this policy vs. mechanism distinction as it applies to CPU scheduling.!1

Mechanism: Context switch are the steps that must be taken to switch which process is using the processor. It involves saving the state of the process currently running (program counter, stack pointer, page table, register contents) and restoring the state associated with the process about to run. Policy: Determine when to switch the running process. This is done by the scheduler. Sample schedulers are FIFO, Round Robin, Shortest Job First and Priority schedulers. Some schedulers try to optimize throughput, others try to optimize response time, etc. 3. One of the things that an operating system does to simplify the programmer s job is to give the illusion that an individual program is the only program running on the computer. Briefly describe how the OS provides this illusion with respect to the computer s memory. The memory inside a process uses a virtual address space. The addresses are generated by the compiler and are independent from the amount of physical memory. When a process is executed, the operating system allocates physical memory to use and stores information about where that physical memory is inside the process s PCB. When instructions are executed, the hardware translates from virtual addresses to physical addresses. This mechanism allows multiple processes to share physical memory, with each process getting some portion of the physical memory. The program, however, is completely unaware of this sharing and refers to memory using its virtual addresses, which are completely independent of the physical addresses, from the program s perspective. 4. For the following C program, which of the following are possible outputs of the program? There may be more than one possible output. You can assume the program compiles and is able to produce at least one of the outputs shown. Briefly explain your choices. int main(int argc, char **argv) { int a = 12; int b = 5; pid_t pid = fork(); if (pid > 0) { b = b + 2; /* What does this output? */ fprintf(stdout,"in parent, a = %d\n",a); fprintf(stdout,"in parent, b = %d\n",b); else { a = a + 3; fprintf(stdout,"in child, a = %d\n",a); fprintf(stdout,"in child, b = %d\n",b);!2

a. In parent, a = 12 In parent, b = 7 In child, a = 15 In child, b = 5 b. In parent, a = 15 In parent, b = 7 In child, a = 15 In child, b = 7 c. In parent, a = 12 In parent, b = 7 In child, a = 15 In child, b = 7 a is the only valid output. The child gets a copy of the parent s memory on fork. They do not share memory. Therefore, only the child sees the update to a and only the parent sees the update to b.!3

5. Answer the following questions about this C program: int main (int argc, char *argv[]) { char *string1 = "cat"; char string2[4]; char *string3 = malloc (strlen (string1) + 1); strcpy (string2, string1); strcpy (string3, string1); The relevant parts of the man page for strcpy say: char *strcpy (char *dest, char *src); The strcpy() function copies the string pointed to by src, including the terminating null byte ( \0 ), to the buffer pointed to by dest. The destination string dest must be large enough to receive the copy. a. (5 points) Will both strcpy calls succeed as they are written? If not, what is the problem? They both work. b. (5 points) What calls to free should you add to avoid all the memory leaks in this function? free (string3)!4

6. Fork / wait a. (3 points) What output would the following C code print? int main (int argc, char *argv[]) { pid_t forked_proc = fork(); if (forked_proc == 0) { printf ("Forked_proc is 0\n"); else if (forked_proc > 0) { wait(null); printf ("Forked_proc is not 0\n"); Forked_proc is 0 Forked_proc is not 0 b. (2 points) If the wait call is omitted, is it possible that the same output would be printed? If not, why not? It is still possible to get the same output. The parent might give up the CPU after forking and before reaching the printf, allowing the child to go first. It is also possible that they will come out in the opposite order.!5

7. Indicate the schedule, average turnaround time, and average response time for the following jobs and scheduling algorithms (show the equations, you do not need to do the arithmetic): Arrival time Job length Job 1 0 9 Job 2 1 9 Job 3 2 5 a. For FIFO i. (3 pts) Schedule: ii. (1 pt) Average turnaround time Job 1 : 0-8 Job 2: 9-17 Job 3: 18-22 ((8-0)+(17-1)+(22-2))/3 = (8 + 16 + 20) / 3= 44/3 = 14.67 iii. (1 pt) Average response time ((0-0)+(9-1)+(18-2))/3 = (0 + 8 + 16) / 3= 24/3 = 8 b. For Shortest-Time-to-Completion-First i. (3 pts) Schedule: ii. (1 pt) Average turnaround time Job 1 : 0-1 Job 3: 2-6 Job 1: 7-13 Job 2: 14-22 ((13-0)+(22-1)+(6-2))/3 = (13 + 21 + 4) / 3= 38/3 = 12.67 iii. (1 pt) Average response time ((0-0)+(14-1)+(2-2))/3 = (0 + 13 + 0) / 3= 13/3 = 4.33 c. For Round Robin with a quantum of 3 i. (3 pts) Schedule: ii. (1 pt) Average turnaround time Job 1 : 0-2 Job 2: 3-5 Job 3: 6-8 Job 1: 9-11 ((19-0)+(22-1)+(16-2))/3 = (19 + 21 + 14) / 3= 54/3 = 18 iii. (1 pt) Average response time Job 2: 12-14 Job 3: 15-16 Job 1: 17-19 Job 2: 20-22!6 ((0-0)+(3-1)+(6-2))/3 = (0 + 2 + 4) / 3= 6/3 = 2

8. Multilevel feedback queue a. (4 pts) What is the purpose of the priority boost? To keep low priority jobs from starving b. (2 pts) What happens if the boost is done too frequently? High priority jobs will not get enough time on the CPU and will become less responsive. The scheduler will behave more like a round robin scheduler. c. (2 pts) What happens if the boost is done infrequently? Low priority jobs will get very little time on the CPU and will take long to complete!7

9. Address translation. For the following addresses, assume that we have 4 segments and an address space of 1024 bytes. Assume that both segments use addresses that grow positive and have the following values for the base and bounds. Your answers should be in hex. Base Bounds Segment 0 0x1adf 0xef Segment 1 0x0505 0xe8 Segment 2 0x23f2 0xa3 Segment 3 0x1cda 0x90 a. (1 pt) How many bits are needed for the segment id? 2 b. (1 pt) How many bits are needed for the offset within a segment? Total address needs 10 bits, so offset will be 8 bits. c. 0x0ed i. (1 pt) Segment #: ii. (1 pt) Offset: 0 0xed = 14*16 + 13 = 237 iii. (1 pt) Is the address valid? yes iv. (2 pts) If the address is valid, show the equation you would use to calculate the physical address, showing the hexadecimal values you would use. You do not need to do the arithmetic. 0x1adf + 0xed d. 0x3f5 i. (1 pt) Segment #: ii. (1 pt) Offset: 3 0xf5 = 15*16 + 5 = 245 iii. (1 pt) Is the address valid? no, the offset is bigger than the bounds iv. (2 pts) If the address is valid, what is the corresponding physical address? not valid!8

!9

10. Mechanism vs. policy. a. (5 pts) Briefly explain the difference between "mechanism" and "policy" in operating systems in general. Mechanism tells us how something is accomplished. Policy tells exactly when and how the mechanism is used. b. (5 pts) Provide an example illustrating the difference with respect to process management. A context switch is the mechanism needed to switch which process is running. Scheduling is defined by a policy that determines when to change which process is running and which process to switch to. 11. (1 point each) For the following CPU instructions, indicate which should only be executed in kernel mode: a. Loading memory into a register ok in user mode b. Setting the address of the timer interrupt handler only in kernel mode c. Setting the values of the base and bounds registers only in kernel mode d. Comparing the value of a register to a constant ok in user mode e. Trap instruction ok in user mode, used to make a system call!10

12. (4 points each) Briefly define the following terms: a. Context switch Mechanism used by the OS to switch which process is running. It saves the register values and memory information of the running process in its PCB. The loads the registers of the process it wants to run from that process s PCB. When it returns from the trap, the program counter will be set to be the process just switched to. b. Preemptive scheduling Preemptive scheduling is any scheduling algorithm that forces a process off the CPU before it voluntarily gives up the CPU. Round Robin is a good example where a process is not allowed to use the CPU for longer than 1 timeslice. c. Internal fragmentation Internal fragmentation is memory that is allocated to a process but the process never uses. This is a big problem with contiguous memory allocation. d. Process control block The PCB contains information about a process that the OS needs to manage it. It also holds information that the CPU needs to resume its execution, like register values, program counter, and where its memory is. e. Heap The heap is the portion of memory used for data. It is used when we make malloc calls and freed up with free calls. It tends to grow over time as the program executes.!11