Sample Mid-Term Exam 2

Similar documents
CS Operating system

CS4411 Intro. to Operating Systems Final Fall points 12 pages

There are 13 total numbered pages, 7 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:

Queues. A queue is a special type of structure that can be used to maintain data in an organized way.

Midterm Exam #2 April 20, 2016 CS162 Operating Systems

Final Exam. 11 May 2018, 120 minutes, 26 questions, 100 points

COMP 3361: Operating Systems 1 Final Exam Winter 2009

CS4411 Intro. to Operating Systems Final Fall points 10 pages

CS140 Operating Systems and Systems Programming Final Exam

Question Points Score Total 100

CSE 120 PRACTICE FINAL EXAM, WINTER 2013

1. [Lock, Monitor and Deadlock: 5 Lectures (=26%)] 16 Marks [ ]

Midterm Exam #2 Solutions April 20, 2016 CS162 Operating Systems

Midterm Exam October 15, 2012 CS162 Operating Systems

(VERSION WITH ANSWERS) CORE EXAMINATION Department of Computer Science New York University September 26, 2008

we are here I/O & Storage Layers Recall: C Low level I/O Recall: C Low Level Operations CS162 Operating Systems and Systems Programming Lecture 18

FAT (32 KB) 216 * 215 = 231 = 2GB

Real-Time Systems / Real-Time Operating Systems EE445M/EE380L.6, Spring 2016

Problem Max Points Score Total 100

P.G.TRB - COMPUTER SCIENCE. c) data processing language d) none of the above

Operating Systems Prof. Allan Gottlieb Practice Final Exam Page 1 Name

CSCI 350: Getting Started with C Written by: Stephen Tsung-Han Sher June 12, 2016

Second Midterm Exam March 21, 2017 CS162 Operating Systems

ESC101N: Fundamentals of Computing End-sem st semester

CS Operating system Spring Final -- May 8, You have 120 min. Good Luck!

Lecture Data layout on disk. How to store relations (tables) in disk blocks. By Marina Barsky Winter 2016, University of Toronto

CS4411 Intro. to Operating Systems Exam 1 Fall points 9 pages

we are here Page 1 Recall: How do we Hide I/O Latency? I/O & Storage Layers Recall: C Low level I/O

Variables Data types Variable I/O. C introduction. Variables. Variables 1 / 14

Final Exam. 12 December 2018, 120 minutes, 26 questions, 100 points

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

CS 222/122C Fall 2016, Midterm Exam

ECE 550D Fundamentals of Computer Systems and Engineering. Fall 2017

KING FAHD UNIVERSITY OF PETROLEUM & MINERALS. Information and Computer Science Department. ICS 431 Operating Systems. Lab # 9.

C Review. MaxMSP Developers Workshop Summer 2009 CNMAT

C Language, Token, Keywords, Constant, variable

CS 241 Data Organization Binary Trees

Topic 6: A Quick Intro To C. Reading. "goto Considered Harmful" History

CS-537: Midterm Exam (Fall 2008) Hard Questions, Simple Answers

CS 3204 Sample Final Exam

CS 550 Operating Systems Spring File System

Q1: /8 Q2: /30 Q3: /30 Q4: /32. Total: /100

CS Operating system Summer Final -- August 12, You have 120 min. Good Luck!

2.c Concurrency Mutual exclusion & synchronization mutexes. Unbounded buffer, 1 producer, N consumers

CS630 Operating System Design, Second Exam, Fall 2014

RCU. ò Walk through two system calls in some detail. ò Open and read. ò Too much code to cover all FS system calls. ò 3 Cases for a dentry:

Computer Science 162, Fall 2014 David Culler University of California, Berkeley Midterm 2 November 14, 2014

VFS, Continued. Don Porter CSE 506

CS140 Operating Systems Final December 12, 2007 OPEN BOOK, OPEN NOTES

Operating Systems Design Exam 2 Review: Fall 2010

M3-R4: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE

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

2 nd Half. Memory management Disk management Network and Security Virtual machine

seg # page # offset

Final Exam 1 /12 2 /12 3 /10 4 /7 5 /4 6 /10 7 /8 8 /9 9 /8 10 /11 11 /8 12 /10 13 /9 14 /13 15 /10 16 /10 17 /12. Faculty of Computer Science

Dynamic Memory Management. Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island

Process Synchronization and Communication

537 Final Exam, Old School Style. "The Job Interview" Name: This exam contains 13 old-school pages.

KINGS COLLEGE OF ENGINEERING DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING ACADEMIC YEAR / ODD SEMESTER

Final Exam Solutions May 11, 2012 CS162 Operating Systems

Name: uteid: 1. CS439H: Fall 2011 Midterm 1

Sections 01 (11:30), 02 (16:00), 03 (8:30) Ashraf Aboulnaga & Borzoo Bonakdarpour

Universidad Carlos III de Madrid Computer Science and Engineering Department Operating Systems Course

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

200 points total. Start early! Update March 27: Problem 2 updated, Problem 8 is now a study problem.

FOR Loop. FOR Loop has three parts:initialization,condition,increment. Syntax. for(initialization;condition;increment){ body;

CprE 288 Introduction to Embedded Systems Exam 1 Review. 1

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

Heap Arrays and Linked Lists. Steven R. Bagley

The Note/1 Driver Design

Q1: /20 Q2: /30 Q3: /24 Q4: /26. Total: /100

Cpt S 122 Data Structures. Course Review Midterm Exam # 1

COMP 3361: Operating Systems 1 Midterm Winter 2009

CPSC/ECE 3220 Fall 2017 Exam Give the definition (note: not the roles) for an operating system as stated in the textbook. (2 pts.

A New Real-time Kernel development on an embedded platform

CS , Fall 2001 Exam 2

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

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

Section 7: Scheduling and Fairness

CS 385 Test 1. 1 Apr 2004

Two hours. Question ONE is COMPULSORY UNIVERSITY OF MANCHESTER SCHOOL OF COMPUTER SCIENCE. Date: Friday 25th January 2013 Time: 14:00-16:00

A Answer All Questions. All Questions Carry Equal Marks.Time: 20 Min. Marks: 10.

ECE 2035 Programming HW/SW Systems Fall problems, 5 pages Exam Three 20 November 2013

Short Notes of CS201

The Journalling Flash File System

Process Synchronization Mechanisms

Type Checking. Prof. James L. Frankel Harvard University

CS201 - Introduction to Programming Glossary By

Real-Time Systems / Real-Time Operating Systems EE445M/EE380L.6, Spring 2015

CSL373/CSL633 Major Exam Solutions Operating Systems Sem II, May 6, 2013 Answer all 8 questions Max. Marks: 56

ECE264 Spring 2014 Exam 2, March 11, 2014

PROCESS SYNCHRONIZATION

CS 241 Honors Concurrent Data Structures

COP Programming Concepts Spring 1999 CLOSED BOOK Exam #1 100 Points NAME

Last class: Today: Paging. Virtual Memory

This exam is worth 60 points, or 30% of your total course grade. The exam contains eight

Implementation of the ART Real Time Micro Kernel

In Java we have the keyword null, which is the value of an uninitialized reference type

CS3733: Operating Systems

Transcription:

Sample Mid-Term Exam 2 CS 5460/6460, Fall 2009 Mid-term date: November 19 Name: Instructions: You have 70 minutes to complete this open-book, open-note, closed-computer exam. Please write all answers in the provided space, plus the back of the exam if necessary. 1) [50 pts] Users of the MT library would like a new operation: int MT_wait_or(sema_t *sem, int tid); This function is a combination of MT sem wait() and MT join(), where the function blocks until either a semaphore is available or another thread has terminated. The result is 1 if the function returns because of a successful wait on the given semaphore, and it returns 2 if the function returns because the given thread terminated. If the semaphore is available and the thread is terminated, then MT wait or() picks one or the other arbitrarily. The following scenarios indicate some of the ways that these operation should work and interact with other MT functions, where means that a thread is performing some unspecified work that does not use sem, while a blank space indicates that the thread is blocked or terminated: Only thread ends: Only semaphore available: Both available: thread 1 thread 2 thread 3 MT sem init(&sem, 0) MT wait or(&sema, 3) MT exit() result here must be 2 thread 1 thread 2 thread 3 MT sem init(&sem, 0) MT wait or(&sema, 3) MT sem signal(&sem) result here must be 1 thread 1 thread 2 thread 3 MT sem init(&sem, 0) MT wait or(&sema, 3) MT sem signal(&sem) MT exit() result here can be 1 or 2 MT sem wait(&sema) continues if thread 2 got 2; blocked if thread 2 got 1 1

Describe using C code changes to the solution for HW4 to add the MT wait or() operation. Portions of the HW4 solution are attached to the end of this exam, including all parts that might need to change, and you can write on those pages as part of your answer. Your answer does not have to be error-free C code, but it should be close to working code. 2

2) [25 pts] Given the sequence of page accesses in the top row below, and given three available frames, show the page contained in each frame for after each page access according to the FIFO, 2nd chance, LRU, and optimal replacement algorithms. Also, show total the number of page faults when using each algorithm. Accesses: 1 2 3 1 4 1 2 3 1 4 1 FIFO Faults: 2nd chance Faults: LRU Faults: optimal Faults: 3

3) [25 pts] Some file systems support filling a file with 0s without taking up blocks on the disk, since a long sequences of 0s can be represented compactly and easily. When data is latter written to part of the file containing 0s, an actual block must be allocated. This feature can be supported in the file system of HW6 by using -1 as a block number to indicate a read-only block that is filled with 0s. As is typical, this zero-filling rule applies only for 0s added to a file through a truncate operation or lseek operation is used to extend the size of the file. (That is, MT fs write() doesn t trigger the use of the -1 page even if the bytes to be written are all 0s.) Also, only when a range of 0s spans an entire block is the -1 block used. For reference, the part of the HW6 that defines the file system format is included at the end of this exam. Does this change affect the maximum useful size of a disk that uses (only) this file system? Why or why not? Are there any new failure modes that can affect a program that calls MT fs functions? Why or why not? Describe how each of the operations MT fs open(), MT fs close(), MT fs unlink(), MT fs read(), MT fs write(), MT fs getpos(), MT fs truncate(), and MT fs lseek() need to change to support -1 as a block number. 4

struct sema int cnt; struct tcb *wait; ; enum thr_state READY = 3333, RUNNING, WAITING, TERMINATED ; struct tcb struct tcb *prev, *next; // linked list pointers struct tcb *all_next; // another linked list struct tcb *wait_q; // queue of threads that have joined this thread int share; long long int vt; long long int start; long long int wake_time; ; static struct tcb *ready_q; static struct tcb *timer_q; static int is_on_queue (struct tcb **q, struct tcb *t); static void add_tail (struct tcb **q, struct tcb *t); static struct tcb *dequeue_head (struct tcb **q); static void remove_queue (struct tcb **q, struct tcb *t); static void make_ready (struct tcb *t) add_tail (&ready_q, t); t->state = READY; static void wake_up (struct tcb *t) t->vt = maxll (t->vt, get_min_vt ()); make_ready (t); static void block_me (void) int res_v; current->state = WAITING; update_current_vt (); save_context (&res_v); if (res_v == 0) current = NULL; dispatch (); 5

static void check_for_expired_timers (void) long long int now = get_real_time (); startover: check_invariants(); if (timer_q) struct tcb *t = timer_q; do if (now >= t->wake_time) remove_queue (&timer_q, t); wake_up (t); goto startover; t = t->next; while (t!= timer_q); void MT_sem_wait (struct sema *sem) while (sem->cnt <= 0) add_tail (&sem->wait, current); block_me (); sem->cnt--; void MT_sem_signal (struct sema *sem) struct tcb *p; p = dequeue_head (&sem->wait); if (p) wake_up (p); sem->cnt++; 6

void MT_sem_init (struct sema *sem, int init_count) sem->cnt = init_count; sem->wait = NULL; void MT_exit (int status) current->state = TERMINATED; current->ret_code = status; while (1) struct tcb *t; t = dequeue_head (&current->wait_q); if (!t) break; wake_up (t); current = NULL; dispatch (); static void init_tcb (struct tcb *t) t->tid = get_new_tid (); t->wait_q = NULL; t->magic = 0xdeadbeef; memset (&t->context, 0, sizeof (ucontext_t)); t->prev = t->next = NULL; int MT_usleep (int us) if (us < 0) return -1; current->wake_time = get_real_time () + us; add_tail (&timer_q, current); block_me (); return 0; 7

int MT_join (int tid, int *result) struct tcb *t, **ot; t = all_threads; ot = &all_threads; /* set t to thread with id tid */ if (t->state!= TERMINATED) add_tail (&t->wait_q, current); block_me (); if (result) *result = t->ret_code; *ot = t->all_next; /* free t */ return 0; int MT_set_share (int share) if (share <= 0 share > 10000) return -1; current->share = share; return 0; 8

File system format from HW6: Disk blocks are 512 bytes. A valid filesystem must contain at least three blocks. The maximum size of a filesystem is the number of blocks that can be described by a signed 32-bit integer (i.e. 2 31 1). The first block on the disk (called the zero block from here on) is special it contains the directory. Its format is as follows, working on the assumption that the zero block has been read into a C array declared as int zero block[128]: zero block[0] int magic1 == 0xabbaabba; zero block[1] int magic2 == 0xf00bf00b; zero block[2] int block size == 512; zero block[3] int block cnt; zero block[4] int free list head; zero block[5] int file0; zero block[6] int file1; zero block[7] int file2; zero block[127] int file122; The two magic numbers are used to implement a crude validity check on MT filesystems: the filesystem code should abort with an error if they do not have the specified values. For purposes of this assignment, block size is always set to 512. block cnt stores the number of blocks that the filesystem contains and free list head contains the block number of the first block on the free list. The first 4 bytes of each free block are required to store an integer pointing to the next block on the list, with -1 indicating the end-of-list. Each of the 123 file entries either contains -1 for a free slot, or the disk block number of the inode of a file in the filesystem. An inode is a disk block containing the meta-data associated with a single file. Its format is as follows, working on the assumption that the zero block has been read into a C array declared as int inode[128]: inode[0] inode[1 16] inode[17] inode[18] inode[19] inode[20] inode[127] int magic == 0xdeadbeef; char filename[64]; int size; int block0; int block1; int block2; int block109; The magic number is used to implement a crude validity check on MT filesystems: the filesystem code should abort with an error if an inode is found to not contain the magic value. The filename is an array of 64 bytes that contains up to 63 characters of filename plus a terminating null byte. size indicates the size of the file in bytes. Finally, the block pointers describe the disk block numbers of data blocks allocated to the file. It is always the case that block 0 stores bytes 0 511 of a file, block 1 stores bytes 512 1023, etc. It can easily be computed that the maximum size of a file in the MT filesystem is about 56 KB (the digital camera in question apparently supports cutting-edge image compression). Every disk block must belong to exactly one of the four categories described above: the zero block, free blocks, inodes, and data blocks. The MT block device driver performs a filesystem validity check at startup time to ensure that this is the case. 9