CMSC 313 Spring 2010 Exam 3 May 17, 2010

Similar documents
Systems programming and Operating systems, 2005 Test Exam

CSCI 237 Sample Final Exam

Systems programming and Operating systems, 2005 Tentamen

There are 16 total numbered pages, 7 Questions. You have 2 hours. Budget your time carefully!

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

ECE 454 Computer Systems Programming

CSCI-UA /2. Computer Systems Organization Lecture 19: Dynamic Memory Allocation: Basics

10.1. CS356 Unit 10. Memory Allocation & Heap Management

Dynamic Memory Allocation. Basic Concepts. Computer Organization 4/3/2012. CSC252 - Spring The malloc Package. Kai Shen

Dynamic Memory Allocation

Introduction to Computer Systems. Exam 2. April 11, Notes and calculators are permitted, but not computers.

Dynamic Memory Allocation: Basic Concepts

Memory Management. q Basic memory management q Swapping q Kernel memory allocation q Next Time: Virtual memory

Today. Dynamic Memory Allocation: Basic Concepts. Dynamic Memory Allocation. Dynamic Memory Allocation. malloc Example. The malloc Package

Process s Address Space. Dynamic Memory. Backing the Heap. Dynamic memory allocation 3/29/2013. When a process starts the heap is empty

Processes. Dr. Yingwu Zhu

Dynamic Memory Allocation: Basic Concepts

Dynamic Memory Allocation I Nov 5, 2002

Physical memory vs. Logical memory Process address space Addresses assignment to processes Operating system tasks Hardware support CONCEPTS 3.

Introduction to Computer Systems. Exam 2. April 10, Notes and calculators are permitted, but not computers.

Dynamic Memory Allocation I

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

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

Today. Dynamic Memory Allocation: Basic Concepts. Dynamic Memory Allocation. Dynamic Memory Allocation. malloc Example. The malloc Package

Memory Allocation II. CSE 351 Autumn Instructor: Justin Hsia

Memory Management. To do. q Basic memory management q Swapping q Kernel memory allocation q Next Time: Virtual memory

Dynamic Memory Allocation. Zhaoguo Wang

Dynamic Memory Allocation. Gerson Robboy Portland State University. class20.ppt

CS 322 Operating Systems Practice Midterm Questions

15-213: Final Exam Review

CS 405G: Introduction to Database Systems. Storage

Operating System Labs. Yuanbin Wu

Introduction to Computer Systems /18 243, fall th Lecture, Oct. 22 th

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

Memory Allocation I. CSE 351 Autumn Instructor: Justin Hsia

CMSC 313 Lecture 13 Project 4 Questions Reminder: Midterm Exam next Thursday 10/16 Virtual Memory

Dynamic Memory Allocation

Disks & Files. Yanlei Diao UMass Amherst. Slides Courtesy of R. Ramakrishnan and J. Gehrke

Assignment 5. CS/ECE 354 Spring 2016 DUE: April 22nd (Friday) at 9 am

Dynamic Memory Alloca/on: Basic Concepts

Disks and I/O Hakan Uraz - File Organization 1

Virtual Memory Outline

Dynamic Memory Alloca/on: Basic Concepts

CMSC 313 Fall2009 Midterm Exam 1 Section 01 October 12, 2009

Exceptional Control Flow Part I Oct. 17, 2002

EECE.4810/EECE.5730: Operating Systems Spring 2017 Homework 1 Solution Due 3:15 PM, Wednesday, 2/1/17

Control Flow. Systemprogrammering 2007 Föreläsning 2 Exceptional Control Flow Part I. Exceptional Control Flow. Altering the Control Flow

CSC 1600 Unix Processes. Goals of This Lecture

Memory management. Johan Montelius KTH

Giving credit where credit is due

Exceptional Control Flow Part I September 22, 2008

UW CSE 351, Winter 2013 Final Exam

Dynamic Memory Allocation

CS61 Section Notes. Section 5 (Fall 2011) Topics to be covered Common Memory Errors Dynamic Memory Allocation Assignment 3: Malloc

Recitation #11 Malloc Lab. November 7th, 2017

Midterm Sample Answer ECE 454F 2008: Computer Systems Programming Date: Tuesday, Oct 28, p.m. - 5 p.m.

Optimizing Dynamic Memory Management

Memory Allocation. Copyright : University of Illinois CS 241 Staff 1

ANITA S SUPER AWESOME RECITATION SLIDES

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

CS 167 Final Exam Solutions

In multiprogramming systems, processes share a common store. Processes need space for:

Module 1: Basics and Background Lecture 4: Memory and Disk Accesses. The Lecture Contains: Memory organisation. Memory hierarchy. Disks.

CS61C : Machine Structures

CS 153 Design of Operating Systems

Operating System. Chapter 3. Process. Lynn Choi School of Electrical Engineering

Project 2 Overview: Part A: User space memory allocation

(In columns, of course.)

CSE 351, Spring 2010 Lab 7: Writing a Dynamic Storage Allocator Due: Thursday May 27, 11:59PM

Review! Lecture 5 C Memory Management !

CS61C : Machine Structures

Dynamic Memory Management

Processes. CS 416: Operating Systems Design, Spring 2011 Department of Computer Science Rutgers University

Memory Allocation I. CSE 351 Autumn Instructor: Justin Hsia

CSE351 Winter 2016, Final Examination March 16, 2016

CSC209 Review. Yeah! We made it!

The UtePC/Yalnix Memory System

Quiz Start Time: 09:34 PM Time Left 82 sec(s)

Chapter 8: Virtual Memory. Operating System Concepts

Exceptional Control Flow Part I

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru Department of Electronics and Communication Engineering

CS201 Latest Solved MCQs

CS 351 Sample Final Exam, Spring 2015

Dynamic Memory Management

Altering the Control Flow

Stanford University Computer Science Department CS 140 Final Exam Dawson Engler Winter 1999

Processes. OS Structure. OS Structure. Modes of Execution. Typical Functions of an OS Kernel. Non-Kernel OS. COMP755 Advanced Operating Systems

Recitation 8 Processes, Signals, Tshlab

Section - Computer Science

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

Understand Computer Storage and Data Types

Processes COMPSCI 386

Heap Arrays and Linked Lists. Steven R. Bagley

CSE351 Spring 2018, Final Exam June 6, 2018

CS 201. Processes. Gerson Robboy Portland State University

Section 2: Processes

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.

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

CS 550 Operating Systems Spring Process II

Transcription:

CMSC 313 Spring 2010 Exam 3 May 17, 2010 Name Score UMBC Username Notes: a. Please write clearly. Unreadable answers receive no credit. b. There are no intentional syntax errors in any code provided with this exam. If you think you see an error that would affect your answer, please bring it to my attention c. This exam is worth 85 points Enjoy the summer at the beach!!

Multiple Choice (2 points each) Write the letter of the BEST answer on the line provided for each question. 1. In the memory hierarchy, level k is considered a cache for level k+1 because A. it's smaller and faster B. it's bigger and slower C. it's always in memory D. it's always on the CPU chip 2. PROM stands for A. Partial Read Only Memory B. Programmable Read Only Memory C. Potential Read Only Memory D. Permanent Read Only Memory 3. (True / False) Using segregated free lists to find a free block in the heap approximates the "best fit" algorithm in terms of memory usage. 4. Dr. Frankenstein has a disk that rotates at 7,200 RPM (8ms per full revolution), has an average seek time of 5ms, and has 1000 sectors per track. How long (approximately) does the average 1-sector access take? A. Not enough information to determine the answer B. 13ms C. 9ms D. 0.5ms 5. A zombie process is created when A. a child process terminates, but its parent process continues to run B. a parent process terminates, but its child process continues to run C. when a process is sent the SIGZOMBIE signal D. the user types "control-z" while the process is running 6. A signal handler is A. a function in the kernel that sends signals B. a function in the kernel that executes when a process receives a signal C. a user function that sends signals D. a user function that executes when a process receives a signal

7. In project 6, we provided code for an implicit list allocator. Many students improved this code by creating a linked list of free blocks. Why did this change increase the performance of the allocator? A. Traversing a linked list is significantly faster than moving from block to block in the implicit list. B. The implicit list had to include every block in memory, but the linked list could just include the free blocks. C. Having a linked list made coalescing significantly faster. D. None of the above. 8. Imagine a process (called process A ) that calls fork( ) three times. If all three child processes terminate before process A is picked by the kernel to be run again, how many times could process A receive SIGCHLD? A. Not enough information to determine B. 1 C. 3 D. 1 or 3 9. With respect to disk storage, the term "rotational latency" refers to A. The number of sectors that pass under the read/write head on each revolution B. The time required to wait for the desired sector to pass under the read/write head C. The time it takes for the disk to make one complete revolution D. The time required to wait for the desired track to pass under the read/write head 10. The system call execl( ) is used to A. create a child process B. load and execute a program C. execute special code in the kernel D. switch to "exec mode" 11. RAM is considered to be "volatile memory" because A. its state is occasionally changed without warning B. its state is lost when power is removed C. its state fluctuates, but is always recoverable D. none of the above 12. Which of the following statements regarding disk storage is FALSE? A. The time to access a sector on a disk is affected by the disk's rotational speed. B. All tracks have the same number of sectors C. A cylinder is a collection of tracks D. Transfer time is generally the smallest component of disk access time

Short Answer 13. (4 points) In no more than 2 sentences, describe the difference between internal fragmentation and external fragmentation. 14. (6 points) What is a "page table"? Describe how a page table is used to implement virtual memory. 15. (6 points) What is a "page fault" and what actions are taken when it occurs?

Heap Memory Allocation 16. (10 points) Consider an allocator with the following specification: a. Uses a single explicit free list. b. All memory blocks have a size that is a multiple of 8 bytes and is at least 16 bytes c. All headers, footers, and pointers are 4 bytes in size d. Headers consist of the block size in the upper 29 bits, a bit indicating if the block is allocated in the lowest bit (bit 0), and a bit indicating if the previous block is allocated in the second lowest bit (bit 1). e. Allocated blocks consist of a header and a payload (no footer) f. Free blocks consist of a header, two pointers for the next and previous free blocks in the free list, and footer at the end of the block. g. All freed blocks are immediately coalesced. h. The heap starts with 0 bytes, never shrinks, and only grows large enough to satisfy memory requests. i. The heap contains only allocated blocks and free blocks. There are is no space used for other data or special blocks to mark the beginning and end of the heap. j. When a block is split, the lower (left) part of the block becomes the allocated part and the upper (right) part becomes the new free block. k. Any newly created free block (whether it comes from a call to free, the upper part of a split block, or the coalescing of several free blocks) is inserted at the beginning of the free list. l. All searches for free blocks start at the head of the list and walk through the list in order. m. If a request can be fulfilled by using a free block, that free block is used. Otherwise the heap is extended only enough to fulfill the request. If there is a free block at the end of the heap, this can be used along with the new heap space to fulfill the request.

Below you are given a series of memory requests as they might appear in a user's program. You are asked to show what the heap looks like after each request is completed using a first fit placement policy. The heap is represented as a row of boxes, where each box is a single block on the heap, and the bottom of the heap is the left-most box. Simulate the calls to malloc( ) or free( ) on the left by marking each block in the corresponding row. In each block you should write the total size (including headers and footers) of the block in bytes and either f or a to mark it as free or allocated, respectively. For example, the following heap contains an allocated block of size 16, followed by a free block of size 32. 16a 32f Simulate the memory requests using FIRST FIT for block allocation ptr1 = malloc(32); ptr2 = malloc(16); 24a ptr3 = malloc(10); ptr4 = malloc(40); free(ptr2); free(ptr4); ptr5 = malloc(20); free(ptr1); ptr6 = malloc(20); free(ptr3);

Dynamic Memory Coding 17. (10 points) Consider a heap memory allocator that uses an implicit free list. Each memory block, either allocated or free, has a size that is a multiple of eight (8) bytes. Thus, (assuming a 32-bit integer) only the 29 higher order bits in the header and footer are needed to record the block size (in bytes), which includes the header and footer. The usage of the remaining 3 lower order bits is as follows: bit 0 indicates the use of the current block: 1 for allocated, 0 for free. bit 1 indicates the use of the previous adjacent block: 1 for allocated, 0 for free. bit 2 is unused and is always set to be 0. Five helper routines are defined to facilitate the implementation of free(void *p). The functionality of each routine is explained in the comment above the function definition. Write the letter of the code that correctly completes the function on the line provided in the function body. /* given a pointer p to the payload of an allocated block, i.e., p is a pointer returned by some previous malloc() call; returns the pointer to the header of the block */ void * header(void* p) void *ptr; ; return ptr; A. ptr = p - 1; B. ptr = (void *)((int *)p - 1); C. ptr = (void *)((int *)p - 4); /* given a pointer to a valid block header or footer, returns the size of the block */ int size(void *hp) int result; ; return result; A. result = (*hp) & ( 0x7); B. result = ((*(char *)hp) & ( 0x5)) >> 3; C. result = (*(int *)hp) & ( 0x7);

/* given a pointer p to the payload of an allocated block, i.e. p is a pointer returned by some previous call to malloc() returns the pointer to the footer of the block */ void * footer(void *p) void *ptr; ; return ptr; A. ptr = p + size(header(p)) - 8; B. ptr = p + size(header(p)) - 4; C. ptr = (int *)p + size(header(p)) - 2; /* given a pointer to a valid block header or footer, returns the state of the current block, 1 for allocated, 0 for free */ int allocated(void *hp) int result; ; return result; A. result = (*(int *)hp) & 0x1; B. result = (*(int *hp)) & 0x0; C. result = (*(int *)hp) 0x1; /* given a pointer to a valid block header, returns the pointer to the header of previous block in memory */ void * prev(void *hp) void *ptr; ; return ptr; A. ptr = hp - size(hp); B. ptr = hp - size(hp - 4); C. ptr = hp - size(hp - 4) + 4;

Process Control 18. (15 points) Consider the following C program. For space reasons, we do not check return codes, so assume that all functions return normally. int main() pid_t pid1, pid2; pid1 = fork(); pid2 = fork(); if (pid1!= 0 && pid2!= 0) printf("a\n"); if (pid1!= 0 pid2!= 0) printf("b\n"); exit(0); Mark the top of each column that represents a valid possible output of this program with Yes and the top of each column which is impossible with No. YES YES YES NO NO

Signals 19. (10 points) Write the output from the following C code in the box below. pid_t pid; int counter = 2; void handler1(int sig) counter = counter - 1; printf("%d", counter); exit(0); int main() signal(sigusr1, handler1); printf("%d", counter); pid = fork( ); if (pid == 0) while(1) ; // simulate doing some work kill(pid, SIGUSR1); wait(null); counter = counter + 1; printf("%d", counter); exit(0); OUTPUT: