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

Similar documents
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 Exam 1 Questions (document version 1.1)

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

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

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

B. V. Patel Institute of Business Management, Computer &Information Technology, UTU

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

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

First Midterm Exam Solutions October 1, 2018 CS162 Operating Systems

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

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

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

CS 3113 Introduction to Operating Systems Midterm October 11, 2018

CS 3113 Introduction to Operating Systems Midterm October 11, 2018

Process Creation in UNIX

Operating systems fundamentals - B06

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

University of Ottawa School of Information Technology and Engineering

Midterm Exam October 15, 2012 CS162 Operating Systems

Section 2: Processes

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

Inter-Process Communication

Operating Systems, laboratory exercises. List 2.

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

CS240: Programming in C

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

CS510 Operating System Foundations. Jonathan Walpole

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

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

Processes COMPSCI 386

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

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

Exam Guide COMPSCI 386

This homework is due by 11:59:59 PM on Thursday, October 12, 2017.

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

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

Delhi Noida Bhopal Hyderabad Jaipur Lucknow Indore Pune Bhubaneswar Kolkata Patna Web: Ph:

CS 322 Operating Systems Practice Midterm Questions

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

Chapter 5 CPU scheduling

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

Chapter 5: Process Scheduling

CHAPTER 2: PROCESS MANAGEMENT

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

CSE 4/521 Introduction to Operating Systems

Indian Institute of Technology, Kharagpur

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

CSci 4061 Introduction to Operating Systems. (Threads-POSIX)

Chapter 5: CPU Scheduling

Process Management 1

Techno India Batanagar Department of Computer Science & Engineering. Model Questions. Multiple Choice Questions:

This exam paper contains 8 questions (12 pages) Total 100 points. Please put your official name and NOT your assumed name. First Name: Last Name:

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

CSCI 4210 Operating Systems CSCI 6140 Computer Operating Systems Homework 3 (document version 1.2) Multi-threading in C using Pthreads

Linux Programming

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

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

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

COMP 3361: Operating Systems 1 Final Exam Winter 2009

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

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

Process Management! Goals of this Lecture!

MC7204 OPERATING SYSTEMS

Chapter 6: CPU Scheduling

PROCESS MANAGEMENT. Operating Systems 2015 Spring by Euiseong Seo

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

Ph.D. Programme in Computer Science. Model Question Paper RESEARCH APTITUDE ASSESSMENT TEST. Time : 2 Hours Max. Marks : 75

Assignment 3 (Due date: Thursday, 10/15/2009, in class) Part One: Provide brief answers to the following Chapter Exercises questions:

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

Operating systems Portfolio

Input and Output System Calls

LSN 13 Linux Concurrency Mechanisms

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

Filesystems (just a bit): File allocation tables, free-bitmaps, free-lists, inodes, and performance considerations.

CMPSC 311- Introduction to Systems Programming Module: Concurrency

CS Operating system

CMPSC 311- Introduction to Systems Programming Module: Concurrency

CSCI 4210 Operating Systems CSCI 6140 Computer Operating Systems Homework 4 (document version 1.1) Sockets and Server Programming using C

CPU Scheduling Algorithms

Processes. CS 475, Spring 2018 Concurrent & Distributed Systems

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

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

Job Scheduling. CS170 Fall 2018

Introduction to Processes

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

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

CMPSC 311- Introduction to Systems Programming Module: Concurrency

Process Management! Goals of this Lecture!

CS 3214 Midterm. Here is the distribution of midterm scores for both sections (combined). Midterm Scores 20. # Problem Points Score

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

Chapter 3 Processes we will completely ignore threads today

Homework 1. b. Can we ensure the same degree of security in a time shared machine as in a dedicated machine? Explain your answer.

CS240: Programming in C

Lecture 2 Process Management

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

Lab 5: Inter-Process Communication

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

Operating Systems Lab

CS , Fall 2003 Exam 2

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

Transcription:

CSCI 4210 Operating Systems CSCI 6140 Computer Operating Systems Sample Final Exam Questions (document version 1.1) WITH SELECTED SOLUTIONS Overview The final exam will be on Tuesday, May 17, 2016 from 11:30AM-2:30PM in Sage 3303 (please arrive early). The final exam will be 180 minutes; therefore, if you have 50% additional time, you will have 270 minutes (e.g., 11:30AM-4:00PM); if you have 100% additional time, you will have 360 minutes (e.g., 11:30AM-5:30PM). The final exam will count as 20% of your final course grade. You may bring two double-sided (or four single-sided) 8.5 x11 crib sheets containing anything you would like; crib sheets will not be collected. Final exams will not be handed back or available per review; however, exams will be graded multiple times to ensure correctness and consistency of grading. Final exam and final course grades will be made available. The final exam will be comprehensive. Sample Midterm Exam Questions 1. Given the following C program, what is the exact output? If multiple outputs are possible, succinctly describe all possibilities. Assume that all system calls complete successfully. Further, assume that the parent process ID is 168, with any child processes numbered 768, 769, 770, etc. int rc; printf( "ONE\n" ); rc = fork(); printf( "TWO\n" ); if ( rc == 0 ) printf( "THREE\n" ); if ( rc > 0 ) printf( "FOUR\n" ); return EXIT_SUCCESS;

2. Given the following C program, what is the exact output? If multiple outputs are possible, succinctly describe all possibilities. Assume that all system calls complete successfully. Further, assume that the parent process ID is 168, with any child processes numbered 768, 769, 770, etc. #include <sys/types.h> #include <sys/wait.h> int x = 150; printf( "PARENT: x is %d\n", x ); printf( "PARENT: forking...\n" ); pid_t pid = fork(); printf( "PARENT: forked...\n" ); if ( pid == 0 ) printf( "CHILD: happy birthday\n" ); x *= 2; printf( "CHILD: %d\n", x ); else wait( NULL ); printf( "PARENT: child completed\n" ); x *= 2; printf( "PARENT: %d\n", x ); return EXIT_SUCCESS; How would the output change if the wait() system call was removed from the code? 2

3. Given the following C program, what is the exact output? If multiple outputs are possible, succinctly describe all possibilities. Assume that all system calls complete successfully. printf( "ONE\n" ); fprintf( stderr, "ERROR: ONE\n" ); int rc = close( 1 ); printf( "==> %d\n", rc ); printf( "TWO\n" ); fprintf( stderr, "ERROR: TWO\n" ); rc = dup2( 2, 1 ); printf( "==> %d\n", rc ); printf( "THREE\n" ); fprintf( stderr, "ERROR: THREE\n" ); rc = close( 2 ); printf( "==> %d\n", rc ); printf( "FOUR\n" ); fprintf( stderr, "ERROR: FOUR\n" ); return EXIT_SUCCESS; 3

4. Given the following C program, what is the exact output? Further, what is the exact contents of the newfile.txt file? If multiple outputs are possible, succinctly describe all possibilities. Assume that all system calls complete successfully. #include <fcntl.h> int fd; close( 2 ); #if 0 close( 1 ); /* <== add this line later... */ #endif printf( "HI\n" ); fflush( stdout ); fd = open( "newfile.txt", O_WRONLY O_CREAT O_TRUNC, 0600 ); printf( "==> %d\n", fd ); printf( "WHAT?\n" ); fprintf( stderr, "ERROR\n" ); close( fd ); return EXIT_SUCCESS; How do the output and file contents change if the second close() system call is uncommented? 4

5. Given the following C program, what is the exact output? Further, what is the exact contents of the newfile.txt file? If multiple outputs are possible, succinctly describe all possibilities. Assume that all system calls complete successfully. Further, assume that the parent process ID is 168, with any child processes numbered 768, 769, 770, etc. #include <fcntl.h> #include <sys/wait.h> int fd; close( 2 ); #if 0 close( 1 ); /* <== add this line later... */ #endif printf( "HI\n" ); fflush( stdout ); fd = open( "newfile.txt", O_WRONLY O_CREAT O_TRUNC, 0600 ); printf( "==> %d\n", fd ); printf( "WHAT?\n" ); fprintf( stderr, "ERROR\n" ); fflush( stdout ); int rc = fork(); if ( rc == 0 ) printf( "AGAIN?\n" ); fprintf( stderr, "ERROR ERROR\n" ); else wait( NULL ); printf( "BYE\n" ); fprintf( stderr, "HELLO\n" ); return EXIT_SUCCESS; How do the output and file contents change if the second close() system call is uncommented? 5

6. Given the following C program, what is the exact output? If multiple outputs are possible, succinctly describe all possibilities. Assume that all system calls complete successfully. Further, assume that the parent process ID is 168, with any child processes numbered 768, 769, 770, etc. int rc; int p[2]; rc = pipe( p ); printf( "%d %d %d\n", getpid(), p[0], p[1] ); rc = fork(); if ( rc == 0 ) rc = write( p[1], "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26 ); if ( rc > 0 ) char buffer[40]; rc = read( p[0], buffer, 8 ); buffer[rc] = '\0'; printf( "%d %s\n", getpid(), buffer ); printf( "BYE\n" ); return EXIT_SUCCESS; 6

7. Given the table of process burst times, arrival times, and priorities shown below, calculate the turnaround time, wait time, and number of preemptions for each process using the following scheduling algorithms: FCFS; SJF; SRT; RR with a time slice of 3 ms; and Priority scheduling with SJF as secondary scheduling algorithm (note that the lower the priority value, the higher priority the process has). PROCESS BURST TIME ARRIVAL TIME PRIORITY -------- ------------ -------------- ---------- P1 7 ms 0 ms 2 P2 5 ms 0 ms 3 P3 5 ms 1 ms 1 P4 6 ms 4 ms 2 8. Write pseudocode for the scheduling algorithms above; for each, determine what the computational complexity of adding a process to the ready queue, of selecting the next process, and of removing a process from the queue. 9. For each scheduling algorithm above, describe whether CPU-bound or I/O-bound processes are favored. 10. For each scheduling algorithm above, describe how starvation can occur (or describe why it never will occur). 11. Given actual burst times for process P shown below and an initial guess of 6 ms, calculate the estimated next burst time for P by using exponential averaging with alpha (α) set to 0.5; recalculate with α set to 0.25 and 0.75. Measured burst times for P are: 12 ms; 8 ms; 8 ms; 9 ms; and 4 ms. SOLUTION: Given α = 0.5, τ 0 = 6 ms, t 0 = 12 ms, t 1 = 8 ms, t 2 = 8 ms, t 3 = 9 ms, t 4 = 4 ms τ 1 = α t 0 + ( 1 - α ) τ 0 = 9 ms τ 2 = α t 1 + ( 1 - α ) τ 1 = 8.5 ms τ 3 = α t 2 + ( 1 - α ) τ 2 = 8.25 ms τ 4 = α t 3 + ( 1 - α ) τ 3 = 8.625 ms τ 5 = α t 4 + ( 1 - α ) τ 4 = 6.3125 ms 12. Describe what happens when a child process terminates; also, what happens when a process that has child processes terminates? 13. In a shell, how might pipe functionality actually be implemented? Describe in detail. 14. Why might fork() fail? Why does a fork-bomb cause a system to potentially crash and how can a fork-bomb be avoided by an operating system? 7

Sample Final Exam Questions 15. Given the following C program, what is the exact output? If multiple outputs are possible, succinctly describe all possibilities. Assume that all system calls and pthread library calls complete successfully. Further, assume that the main thread ID is 1984, with any child threads numbered 100, 101, 102, etc. #include <pthread.h> void * action( void * arg ) int t = *(int *)arg; printf( "THREAD %u: I'm alive %d\n", (unsigned int)pthread_self(), t ); sleep( t ); return NULL; pthread_t tid[4]; int i, t; for ( i = 0 ; i < 4 ; i++ ) t = 1 + i * 3; printf( "MAIN: Creating thread for task %d\n", t ); pthread_create( &tid[i], NULL, action, &t ); for ( i = 0 ; i < 4 ; i++ ) pthread_join( tid[i], NULL ); printf( "MAIN: Joined child thread %u\n", (unsigned int)tid[i] ); return 0; 16. What is the behavior of the given code if the second for loop (i.e., the loop that includes the pthread_join() call) is entirely removed? 17. Describe how the inconsistencies in the child threads (i.e., in terms of their inputs) would be corrected in the above code. 8

SOLUTION TO 15: This program displays the three blocks of output shown below. Block A: MAIN: Creating thread for task 1 MAIN: Creating thread for task 4 MAIN: Creating thread for task 7 MAIN: Creating thread for task 10 Block B: THREAD 100: I'm alive 1 (or 4 or 7 or 10) THREAD 101: I'm alive 4 (or 7 or 10) THREAD 102: I'm alive 7 (or 10) THREAD 103: I'm alive 10 Block C: MAIN: Joined child thread 100 MAIN: Joined child thread 101 MAIN: Joined child thread 102 MAIN: Joined child thread 103 For Blocks A and C, the output shown above must appear in the given relative order (i.e., the four lines of Block A must be in the order shown, and the four lines of Block C must be in the order shown). For Block B, the four lines of output may be in any order. Further, because local variable t is statically allocated in the main() function, each thread receives the address of this variable. Therefore, thread 100 may see the contents of t contain 1, 4, 7, or 10; thread 101 may see the contents of t contain 4, 7, or 10; and thread 102 may see the contents of t contain 7 or 10. For each thread (i.e., 100 to 103), there are three corresponding lines of output in Block A, Block B, and Block C, which must be in block order, e.g., as shown below for thread 100: MAIN: Creating thread for task 1 THREAD 100: I'm alive 1 (or 4 or 7 or 10) MAIN: Joined child thread 100 SOLUTION TO 16: If the second for loop is removed, the main thread does not wait for the child threads. Therefore, output from Block C above is not displayed. Further, output from Block B may or may not be displayed, since the main thread might exit (i.e. thus terminating the entire process) before the child threads are done. SOLUTION TO 17: As noted above in the solution to 15, variable t is statically allocated in the main() function. To correct this and ensure that each thread gets its own correct value of t, memory should be dynamically allocated at each iteration of the first for loop. 9

18. Contiguous Memory Allocation: Consider a contiguous memory allocation scheme with dynamic partitioning for a 64MB physical memory with five pre-allocated processes (i.e., A, B, C, D, and E) that just happen to have memory requirements that are evenly divisible by 1MB. Given new processes F, G, and H) that arrive (almost) simultaneously in the order shown below, show how memory allocation occurs for each of the given placement algorithms. Arrival Order ProcessID Memory Requirements ======================================================= 1 F 2,987,642 bytes 2 G 4,002,016 bytes 3 H 6,202,454 bytes ======================================================= Note that if a process cannot be placed, be sure to state that, then move on to the next process. Do not perform defragmentation. For the memory allocation shown below, apply the First Fit algorithm: Memory: AAAAAAAAA...B BBBBBB...CCCCC CCCC...DDDDDDDDD DDDD...EEE (each character here represents 1MB) For the memory allocation shown below, apply the Best Fit algorithm: Memory: AAAABBBBBBBBBBBB BBBBBBBB...CCCC CCCCC...DDDDDDDD DDDDDD...EEE For the memory allocation shown below, apply the Next Fit algorithm, with process D being the last-placed process: Memory: AAAAAAAAAA...B BBBBBBBB...CCC CCCCCC...DDDDDDD DDDD...EEEE 19. For each of the above algorithms, how much space is unused after the processes are allocated to memory? 20. For each of the above, what kind of fragmentation occurs (i.e., internal or external)? 10

SOLUTIONS TO 18, 19, AND 20: First, please note that 1MB is 2 20 or 1,048,576 bytes. After the First Fit algorithm is applied: Memory: AAAAAAAAAFFF...B (F uses 2,987,642 bytes of 6MB free) BBBBBBGGGG.CCCCC (G uses 4,002,016 bytes of 5MB free) CCCC...DDDDDDDDD DDDDHHHHHH...EEE (H uses 6,202,454 bytes of 9MB free) There is therefore external fragmentation, calculated as follows: ( 6MB - 2,987,642 ) + ( 5MB - 4,002,016 ) + 3MB + ( 9MB - 6,202,454 ) After the Best Fit algorithm is applied: Memory: AAAABBBBBBBBBBBB BBBBBBBBGGGGCCCC (G uses 4,002,016 bytes of 4MB free) CCCCCFFFDDDDDDDD (F uses 2,987,642 bytes of 3MB free) DDDDDDHHHHHH.EEE (H uses 6,202,454 bytes of 7MB free) There is therefore external fragmentation, calculated as follows: ( 4MB - 4,002,016 ) + ( 3MB - 2,987,642 ) + ( 7MB - 6,202,454 ) After the Next Fit algorithm is applied: Memory: AAAAAAAAAA...B BBBBBBBB...CCC CCCCCC...DDDDDDD DDDDFFFGGGG.EEEE (F uses 2,987,642 bytes and G uses 4,002,016 bytes of 8MB free) (H cannot be placed) There is therefore external fragmentation, calculated as follows: ( 8MB - 2,987,642-4,002,016 ) + 5MB + 5MB + 3MB 11

21. Noncontiguous Memory Allocation: Consider a noncontiguous memory allocation scheme in which a logical memory address is represented using 32 bits. Of these bits, the high-order 12 bits represent the page number; the remaining bits represent the page offset. What is the total logical memory space (i.e., how many bytes are addressed)? SOLUTION: 2 32 How many pages are there? SOLUTION: 2 12 What is the page size? SOLUTION: 2 20 What is the frame size? SOLUTION: 2 20 (same as page size) How does logical memory address 23,942,519 (binary 1011011010101010101110111) map to physical memory (i.e., what is the logical page number and page offset)? SOLUTION: page number is 10110 (i.e., 0000010110); page offset is 11010101010101110111 If a process requires 78,901,234 bytes of memory, how many pages will it require? SOLUTION: ans = ceil( 78,901,234 / 2 20 ) How many bytes are unused due to external fragmentation? SOLUTION: 0 (there is no external fragmentation, because the entirety of physical memory is partitioned into equally sized frames) How many bytes are unused due to internal fragmentation? SOLUTION: ( 2 20 ans ) - 78,901,234 Given that the page table is stored entirely in memory and a memory reference takes 100 nanoseconds, how long does a paged memory reference take? SOLUTION: 200 ns Adding a translation look-aside buffer (TLB) with a TLB access time of 15 nanoseconds, how long does a paged memory reference take if a TLB hit occurs? SOLUTION: 115 ns Given a TLB hit ratio of 84%, what is the effective memory access time (EMAT)? SOLUTION: 0.84 115 ns + 0.16 215 ns 12

22. Virtual Memory: Given a page reference string and an n-frame memory, how many page faults occur for the following page replacement algorithms: FIFO; OPT; LRU; LFU. Page Reference Stream: 1 8 4 8 4 3 8 3 4 7 1 7 2 3 2 4 2 7 8 23. Given a page reference string and a working set delta, identify the working set at the point indicated below. Page Reference Stream: 1 8 4 8 4 3 8 3 4 7 1 7 2 3 2 4 2 7 8 ^ Use a delta of 3, 5, then 8. SOLUTION: If the delta value does not include the current page reference, then: working set with delta of 3 is 3, 4, 7, 8; working set with delta of 5 is also 3, 4, 7, 8; working set with delta of 8 is also 3, 4, 7, 8; if we set delta to 9, working set is 1, 3, 4, 7, 8 If the delta value does include the current page reference, then: working set with delta of 3 is 3, 4, 7; working set with delta of 5 is also 3, 4, 7, 8; and working set with delta of 8 is also 3, 4, 7, 8 Either will be correct (i.e., both approaches are a valid way of using the delta value). 13