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

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 Final Exam Questions (document version 1.1) 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)

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

University of Ottawa School of Information Technology and Engineering

Operating systems fundamentals - B06

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

First Midterm Exam Solutions October 1, 2018 CS162 Operating Systems

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

Process Creation in UNIX

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

Operating Systems, laboratory exercises. List 2.

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

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

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

Linux Programming

CS510 Operating System Foundations. Jonathan Walpole

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

CS240: Programming in C

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

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

CS 3113 Introduction to Operating Systems Midterm October 11, 2018

CS 3113 Introduction to Operating Systems Midterm October 11, 2018

CMPSC 311- Introduction to Systems Programming Module: Concurrency

CSE 4/521 Introduction to Operating Systems

CMPSC 311- Introduction to Systems Programming Module: Concurrency

ECE 598 Advanced Operating Systems Lecture 23

Chapter 3 Processes we will completely ignore threads today

Operating Systems Lab

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

CMPSC 311- Introduction to Systems Programming Module: Concurrency

LSN 13 Linux Concurrency Mechanisms

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

CSCI 4210 Operating Systems CSCI 6140 Computer Operating Systems Project 2 (document version 1.4) CPU Scheduling Algorithms

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

Inter-Process Communication

CHAPTER 2: PROCESS MANAGEMENT

CMPT 300: Operating Systems I Assignment 1

Computer Science 162, Fall 2014 David Culler University of California, Berkeley Midterm 1 September 29, 2014

Processes COMPSCI 386

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

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

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

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

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

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

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

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

Chapter 5: CPU Scheduling

Section 2: Processes

Compile the Hello World program

CS 3305 Intro to Threads. Lecture 6

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

Lab 5: Inter-Process Communication

First Midterm Exam September 28, 2017 CS162 Operating Systems

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

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

Operating Systems. Review ENCE 360

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

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

Introduction to Processes

The course that gives CMU its Zip! Concurrency I: Threads April 10, 2001

Processes. Processes (cont d)

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

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

Input and Output System Calls

CSEN 602-Operating Systems, Spring 2018 Practice Assignment 2 Solutions Discussion:

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

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

CS 350 : COMPUTER SYSTEM CONCEPTS SAMPLE TEST 2 (OPERATING SYSTEMS PART) Student s Name: MAXIMUM MARK: 100 Time allowed: 70 minutes

Chapter 5: Process Scheduling

Solutions to the first midterm. COSC 4330/6310 Summer 2013

Process Management 1

Pipelines, Forks, and Shell

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

Reading Assignment 4. n Chapter 4 Threads, due 2/7. 1/31/13 CSE325 - Processes 1

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

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

everything is a file main.c a.out /dev/sda1 /dev/tty2 /proc/cpuinfo file descriptor int

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

Lecture 2 Process Management

PROCESS MANAGEMENT. Operating Systems 2015 Spring by Euiseong Seo

First Midterm Exam September 28, 2017 CS162 Operating Systems

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

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

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

Operating Systems. Lecture 06. System Calls (Exec, Open, Read, Write) Inter-process Communication in Unix/Linux (PIPE), Use of PIPE on command line

Process Management! Goals of this Lecture!

Process Management! Goals of this Lecture!

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

High Performance Computing Course Notes Shared Memory Parallel Programming

Chapter 5 CPU scheduling

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

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

pthreads CS449 Fall 2017

UNIX input and output

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

Discussion of Assignments 2. Line buffered vs. full buffered I/O. Some often encountered issues in the submissions.

Operating systems Portfolio

Transcription:

CSCI 4210 Operating Systems CSCI 6140 Computer Operating Systems Sample Midterm Exam Questions (document version 1.1) Overview The midterm exam will be in class on Monday, March 28, 2016 from 10:00-11:45AM (please arrive early). The midterm exam will be 105 minutes; therefore, if you have 50% additional time, you will have 160 minutes; if you have 100% additional time, you will have 210 minutes. The midterm exam will count as 16% of your final course grade. You may bring one double-sided (or two single-sided) 8.5 x11 crib sheets containing anything you would like; crib sheets will not be collected. Midterm exams will be handed back and reviewed on Monday, April 4, 2016. Grade grievances must be made no later than Monday, April 11, 2016 by handing your exam back to Professor Goldschmidt (after class or during office hours). The midterm exam will cover everything we have done this semester up to and including threads. 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" );

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 ); 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" ); 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 ); 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" ); 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" ); 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 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. 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

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 100, with any child threads numbered 200, 201, 202, 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