CS 3113 Introduction to Operating Systems Midterm October 11, 2018

Similar documents
CS 3113 Introduction to Operating Systems Midterm October 11, 2018

CS 2334: Programming Structures and Abstractions: Exam 1 October 3, 2016

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

CS : Introduction to Computer Programming Final Exam December 9, Please wait to open this exam booklet until you are told to do so.

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

Fall 2015 COMP Operating Systems. Lab #3

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

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

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

UNIVERSITY OF NEBRASKA AT OMAHA Computer Science 4500/8506 Operating Systems Fall Programming Assignment 1 (updated 9/16/2017)

CS : Introduction to Computer Programming Final Exam December 9, Please wait to open this exam booklet until you are told to do so.

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

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

Process Creation in UNIX

CSE 333 Midterm Exam 2/12/16. Name UW ID#

ECE264 Fall 2013 Exam 3, November 20, 2013

628 Lecture Notes Week 4

Computer Science 2500 Computer Organization Rensselaer Polytechnic Institute Spring Topic Notes: C and Unix Overview

CpSc 1010, Fall 2014 Lab 10: Command-Line Parameters (Week of 10/27/2014)

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 20

Programs. Function main. C Refresher. CSCI 4061 Introduction to Operating Systems

25.2 Opening and Closing a File

PRINCIPLES OF OPERATING SYSTEMS

OS lpr. www. nfsd gcc emacs ls 9/18/11. Process Management. CS 537 Lecture 4: Processes. The Process. Why Processes? Simplicity + Speed

518 Lecture Notes Week 3

Final Exam. Fall Semester 2016 KAIST EE209 Programming Structures for Electrical Engineering. Name: Student ID:

File IO and command line input CSE 2451

Figure 1 Ring Structures

OS lpr. www. nfsd gcc emacs ls 1/27/09. Process Management. CS 537 Lecture 3: Processes. Example OS in operation. Why Processes? Simplicity + Speed

CSC209 Review. Yeah! We made it!

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

Operating System Labs. Yuanbin Wu

15-213/18-243, Spring 2011 Exam 2

CS 33. Shells and Files. CS33 Intro to Computer Systems XX 1 Copyright 2017 Thomas W. Doeppner. All rights reserved.

File Access. FILE * fopen(const char *name, const char * mode);

CSCI-243 Exam 2 Review February 22, 2015 Presented by the RIT Computer Science Community

Killing Zombies, Working, Sleeping, and Spawning Children

Getting to know you. Anatomy of a Process. Processes. Of Programs and Processes

Lecture 03 Bits, Bytes and Data Types

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

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

CS 322 Operating Systems Practice Midterm Questions

CSci 4061 Introduction to Operating Systems. Programs in C/Unix

Process Management! Goals of this Lecture!

Preview. Interprocess Communication with Pipe. Pipe from the Parent to the child Pipe from the child to the parent FIFO popen() with r Popen() with w

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

System Programming. Introduction to Unix

Computer Science 330 Operating Systems Siena College Spring Lab 5: Unix Systems Programming Due: 4:00 PM, Wednesday, February 29, 2012

Contents. NOTICE & Programming Assignment #1. QnA about last exercise. File IO exercise

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

Naked C Lecture 6. File Operations and System Calls

The course that gives CMU its Zip! I/O Nov 15, 2001

Creating a Shell or Command Interperter Program CSCI411 Lab

CS167 Programming Assignment 1: Shell

Process Management 1

Computer Systems Assignment 2: Fork and Threads Package

Layers in a UNIX System. Create a new process. Processes in UNIX. fildescriptors streams pipe(2) labinstructions

All the scoring jobs will be done by script

All the scoring jobs will be done by script

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

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

UNIVERSITY OF TORONTO SCARBOROUGH Computer and Mathematical Sciences. APRIL 2016 EXAMINATIONS CSCB09H3S Software Tools & Systems Programming

CS Operating Systems Lab 3: UNIX Processes

Darshan Institute of Engineering & Technology for Diploma Studies Unit 6

www nfsd emacs lpr Process Management CS 537 Lecture 4: Processes Example OS in operation Why Processes? Simplicity + Speed

CITS2002 Systems Programming. Creating a new process using fork() 1 next CITS2002 CITS2002 schedule

CS240: Programming in C. Lecture 14: Errors

EE 312 Fall 2018 Midterm 1 Version A October 10, 2018

First Midterm Exam Solutions October 1, 2018 CS162 Operating Systems

Lecture 7: file I/O, more Unix

Computer Science & Engineering Department I. I. T. Kharagpur

UNIX System Calls. Sys Calls versus Library Func

CS240: Programming in C

CSE 303 Midterm Exam

Lecture 3. Introduction to Unix Systems Programming: Unix File I/O System Calls

Processes. Johan Montelius KTH

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

Section 2: Processes

CSE 333 SECTION 3. POSIX I/O Functions

CS240: Programming in C

Lecture 23: System-Level I/O

MIDTERM EXAM. CS 217 October 28, Name: Precept: Honor Code: Score: Problem Score Max

Project 1 System Calls

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

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

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

A process. the stack

Organization of a file

Unit 6 Files. putchar(ch); ch = getc (fp); //Reads single character from file and advances position to next character

CS 370 Operating Systems

CSE 333 Midterm Exam July 24, Name UW ID#

CSC209: Software tools. Unix files and directories permissions utilities/commands Shell programming quoting wild cards files

CSC209: Software tools. Unix files and directories permissions utilities/commands Shell programming quoting wild cards files. Compiler vs.

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

CS510 Operating System Foundations. Jonathan Walpole

Processes. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Recitation 8: Tshlab + VM

CS , Fall 2003 Exam 2

Common Misunderstandings from Exam 1 Material

2009 S2 COMP File Operations

Transcription:

General instructions: CS 3113 Introduction to Operating Systems Midterm October 11, 2018 Please wait to open this exam booklet until you are told to do so. This examination booklet has 10 pages. You also have been issued a bubble sheet. Write your name, university ID number and date, and sign your name below. Also, write your name and ID number on your bubble sheet, and fill in the bubbles for your ID. The exam is closed book, notes and electronic devices. The exception is that you may have one page of personal notes (double sided). The exam is worth a total of 137 points (and 15% of your final grade). You have 1.25 hours to complete the exam. Be a smart test taker: if you get stuck on one problem go on to the next. Use your bubble sheet to answer all multiple-choice questions. Make sure that the question number and the bubble row number match when you are answering each question. If you cannot effectively erase an incorrect answer, mark an X over it. On my honor, I affirm that I have neither given nor received inappropriate aid in the completion of this exam. Signature: Name: ID Number: Date: Question Points Score Files and File Systems 39 Memory and Memory Management 21 Program Compilation 13 System Calls 15 Processes 37 Serial Processing 12 Total: 137

Part I. Files and File Systems 1. (3 points) True or False? When two processes simultaneously and independently open the same file name, they maintain independent file contents. 2. (6 points) Given the following partition configuration and the commands below, what is printed by the shell from the last command? (ignore spacing and newlines in the answer) Partition: /dev/sda1, mounted as root (i.e., /) / tmp/ bin/ scratch/ data/ home/ linus/ bob/ Partition: /dev/sdb2 / brian/ projects/ notes/ ada/ difference/ engine/ Shell commands: mount t ext3 /dev/sdb2 /home ls /scratch A. data B. brian ada C. linus bob D. File not found 3. (6 points) Given the above configuration and mount command, what is printed by the shell in response to this command? (ignore spacing and newlines in the answer) ls /home A. data B. brian ada C. linus bob D. File not found Page 2

4. (6 points) Assume the initial contents of file myfile2 and the execution of the following block of code. What are the final contents of myfile2? Assume that there no errors with permissions. myfile2 initial contents: foo bar baz Code block: int fd = open( myfile2, O_WRONLY ) ; if (fd == 1){ printf( Error ) ; exit( 1); if (lseek(fd, 3, SEEK_SET ) == 1) { printf( Error ) ; exit( 1); write(fd, BAZ, 3) ; close(fd) ; A. BAZ B. foo bar baz C. foo bar baz BAZ D. foo BAZ baz 5. (3 points) True or False? In the Linux ext file system, an i-node contains information about the owner of a file. Page 3

6. (6 points) Assume the initial contents of file myfile and the execution of the following block of code. What are the final contents of myfile? Assume that there no errors with permissions and that there are no newlines. myfile initial contents: pass Code block: FILE fp = fopen( myfile, a ) ; if (fp == NULL){ printf( Error ) ; exit( 1); fprintf (fp, the exam ) ; fclose(fp) ; A. pass B. the exam C. pass the exam D. There is an error 7. (3 points) True or False? When two processes simultaneously and independently open the same file name, they maintain independent file offsets. 8. (3 points) True or False? In the Linux ext file system, an i-node contains the contents of a file. 9. (3 points) True or False? The read() system call always returns the number of bytes read. Page 4

Part II. Memory and Memory Management 10. (3 points) True or False? The physical memory allocated to a process at a given time must be contiguous. 11. (5 points) As you travel up the memory hierarchy (to the smallest-sized memory) which of the following is true? A. Decreasing cost per bit and increasing access time B. Increasing cost per bit and increasing access time C. Increasing cost per bit and decreasing access time D. Decreasing cost per bit and decreasing access time 12. (5 points) Below is a list of properties of memory (assuming a C compiler). Mark the one item that is more true for the heap than the stack. A. Faster allocation B. Automatic memory management C. Local memory storage D. Global memory storage E. Persistent after function returns 13. (3 points) True or False? All memory accessible by a process is exclusively owned by that process. 14. (5 points) A new stack frame is created when function A calls function B. This stack frame does not contain which one of the following? A. A copy of the registers used by function A B. Local variables for function B C. Address of function B D. Address inside A where B is called E. The return value for function B Page 5

Part III. Program Compilation 15. (6 points) Consider a program that is implemented as two distinct source files (part1.c and part2.c) to create a single executable zformat. On which line is the bug in the following Makefile that prevents the executable from being compiled? 1 CC = gcc 2 CFLAGS = Wall g 3 ALL = zformat 4 5 all : (ALL) 6 7 part1.o: part1.c 8 (CC) c (CFLAGS) part1.c o part1.o 9 10 part2.o: part2.c 11 (CC) c (CFLAGS) part2.c o part2.o 12 13 zformat : 14 (CC) (CFLAGS) part1.o part2.o o zformat 15 16 clean : 17 rm.o (ALL) A. 5 B. 8 C. 13 D. 14 16. (3 points) True or False? Assuming no bugs in the above Makefile, the clean command deletes all files that make all creates. 17. (4 points) The gcc executable performs a number of different functions. Which one of these is responsible for combining multiple object files into a single, executable file? A. Linker B. C Preprocessor C. Compiler D. Answer not shown Page 6

Part IV. System Calls 18. (5 points) A system call provides detailed error information back to the user program by doing what? (pick the best answer) A. Returning an error code B. Printing an error message to STDOUT C. Sending an error message to the system log D. Setting the global variable errno 19. (3 points) True or False? A process must be in kernel mode in order to allocate a new stack frame. 20. (4 points) Which one of the following is not a sys call or sys call wrapper? A. fork() B. wait() C. open() D. read() E. printf() 21. (3 points) True or False? A process must be in kernel mode in order to output data to a USB stick. Page 7

Part V. Processes 22. (3 points) True or False? In the 5-state process model, a process in the blocked state can move directly to the running state. 23. (5 points) What information is not kept in the Process Control Block? (select one) A. Accounting information B. ID number of the process C. Address of memory storing the stack and heap D. State of the processor registers E. The current offset in an open file 24. (5 points) Which of the follow describes a critical section? A. A block of memory that is reserved for the operating system B. A block of memory that is reserved for a process C. A block of memory that is shared between two processes D. A sequence of operations that should not be interrupted 25. (3 points) True or False? As a result of a fork(), a child receives a complete copy of the parent s process control block. 26. (6 points) What is output by this program? Assume no errors in executing system calls. int main(int argc, char argv) { for(int i = 1; i < 6; ++i) { int pid = fork() ; if (pid == 0) { i++; printf( %d, i) ; exit(0) ; else{ waitpid(pid) ; A. 24 B. 246 C. 12345 D. 23456 Page 8

27. (5 points) In the following program, the parent process is to send an int to the child, which then prints out the value. On which line is there a bug? 1 int main(int argc, char argv) 2 { 3 int filedes [2]; 4 5 if (pipe(filedes ) == 1) { 6 fprintf (stderr, Error\n ) ; 7 exit( 1); 8 9 10 int pid ; 11 if ((pid = fork() ) == 1) { 12 fprintf (stderr, Error\n ) ; 13 exit( 1); 14 else if (pid > 0){ 15 close(filedes [1]) ; 16 int val = 42; 17 write(filedes [0], &val, sizeof( int )) ; 18 sleep(1) ; 19 else{ 20 close(filedes [1]) ; 21 close(0) ; 22 dup2(filedes [0], 0) ; 23 24 int myval ; 25 if (read(0, &myval, sizeof( int ))!= sizeof( int )){ 26 fprintf(stderr, Error\n ) ; 27 exit( 1); 28 29 printf( Got: %d\n, myval) ; 30 31 A. 15 B. 20 C. 22 D. 25 E. There is no bug 28. (5 points) What information is kept in the Process Control Block? (select one) A. Value of errno B. Return address for the currently executing function C. Return value for the currently executing function D. Priority of the process E. Global variable values 29. (5 points) An active process that is not located in main memory is necessarily in what type of state? A. Blocked B. Ready C. Running D. Suspended Page 9

Part VI. Serial Processing 30. (6 points) What is output by this program when invoked as indicated? int main(int argc, char argv) { char str [100]; strncpy (str, Hello, World, 13) ; strncpy (str, argv [1], 5) ; printf( %s\n, str) ;./a.out Ciao A. Ciao B. Ciaoo, World C. Hello, World D. Hello, WorldCiao 31. (6 points) The following function is to interpret a sequence of zeros and ones as a binary number and return the corresponding value. It will continue to accept digits until a non-binary character is received. For example: 1, 0, 1, will result in the value 5 being returned. And the sequence 1, 1, will result in the value 3 being returned. 1 long get_binary () 2 { 3 char c; 4 int flag = 1; 5 long value = 0; 6 7 while (flag == 1) 8 { 9 c = getchar () ; 10 if (c >= ³0 ³ && c <= ³1 ³) 11 { 12 value = value 10 + c ³0 ³ ; 13 14 else 15 { 16 flag = 0; 17 18 19 return value ; 20 On which line is the bug? A. 10 B. 12 C. 13 D. 17 E. There is no bug Page 10