Andrew login ID Full Name Section 15 213 18 243 Spring 2011 Exam 2 Thursday April 21 2011 v1 Instructions Make sure that your exam is not missing any sheets then write your Andrew login ID full name and section on the front This exam is closed book and closed notes A notes sheet is attached to the back Write your answers in the space provided below the problem If you make a mess clearly indicate your final answer The exam has a maximum score of 100 points The problems are of varying difficulty The point value of each problem is indicated Good luck 1 12 2 15 3 20 4 18 5 10 6 15 7 10 TOTAL 100 Page 1 of 14 Problem 1 12 points Multiple choice Write the correct answer for each question in the following table 1 2 3 4 5 6 7 8 9 10 11 12 13 X 14 X 15 X 16 X 17 X 18 X 19 X 20 X 1 What kind of process can be reaped a Exited b Running c Stopped d Both a and c 2 Which of the following functions will always return exactly once a exec b exit c fork d None of the above 3 Given an arbitrary malloc implementation that does not coalesce and a second implementation that is identical except it does coalesce which of the following is true about their utilization scores on an arbitrary trace You may assume the first implementation stores enough information to make coalescing possible so the only difference is that the second implementation actually performs the coalescing a The coalescing malloc will definitely get a better utilization score b The coalescing malloc might get a better utilization score and might get the same utilization score but it cannot get a worse utilization score c The coalescing malloc might get a better utilization score might get the same utilization score and might get a worse utilization score d The coalescing malloc will definitely get a worse utilization score Page 2 of 14 4 Which of the following is a reason next fit might perform better than first fit a If a large number of small blocks are stored at the beginning of the free list next fit avoids walking through those small blocks upon every allocation b First fit requires a traversal of the entire free list but next fit does not c First first requires that both allocated and unallocated blocks be examined and next fit examines only free blocks d Next fit is an approximation of best fit so it reduces internal fragmentation compared to first fit 5 How much virtual memory can be addressed by a 32 bit system a b c d 2GB 4GB 8GB 240TB 6 Which of the following is a reason why a virtual memory translation would fault a b c d Page is not present Page is read only Page is empty All of the above 7 How many bits are needed for the Virtual Page Offset if page size is 5000 bytes a b c d 10 11 12 13 8 Which of the following is preserved across exec a b c d Signal handlers Blocked signals a and b Neither 9 In what section of an ELF binary are initialized variables located a b c d symtab data bss text Page 3 of 14 10 What does the call dup2 oldfd newfd do a newfd and oldfd now both refer to oldfd s entry in the open file table b A copy of oldfd s open file table entry is made and newfd points to the copy c A copy of the file oldfd is pointing to is made on the filesystem The file is then opened and newfd points to that open file entry d The numerical value in oldfd is copied into newfd No changes are made in the system 11 Which of the following are shared between a parent and child process immediately following a fork a Writeable physical memory b File descriptor tables c Instruction pointer d Open file structs 12 Which signals cannot be handled by the process a SIGTSTP b SIGKILL c SIGTERM d All of the Above Page 4 of 14 Problem 2 15 points Process control What are the possible output sequences from the following program int main if fork 0 printf a exit 0 else printf b waitpid 1 NULL 0 printf c exit 0 A Circle the possible output sequences abc acb Page 5 of 14 bac bca cab cba B What is the output of the following program pid t pid int counter 2 void handler1 int sig counter counter 1 printf d counter fflush stdout exit 0 int main signal SIGUSR1 handler1 printf d counter fflush stdout if pid fork 0 while 1 kill pid SIGUSR1 waitpid 1 NULL 0 counter counter 1 printf d counter exit 0 OUTPUT Page 6 of 14 Problem 3 20 points Dynamic memory allocation In this question we will consider the utilization score of various malloc implementations on the following code define N 64 void pointers N int i for i 0 i N i pointers i malloc 8 for i 0 i N i free pointers i for i 0 i N i pointers i malloc 24 Page 7 of 14 A Consider a malloc implementation that uses an implicit list with headers of size 8 bytes and no footers In order to keep payloads aligned to 8 bytes every block is always constrained to have size a multiple of 8 The header of each block stores the size of the block and since the 3 lowest order bits are guaranteed to be 0 the lowest order bit is used to store whether the block is allocated or free A first fit allocation policy is used If no unallocated block of a large enough size to service the request is found sbrk is called for the smallest multiple of 8 that can service the request No coalescing or block splitting is done NOTE You do NOT need to simplify any mathematical expressions Your final answer may include multilpliations additions and divisions 1 After the given code sample is run how many total bytes have been requested from sbrk 2 How many of those bytes are used for currently allocated blocks including internal fragmentation and header information 3 How many of those bytes are used to store free blocks including header information 4 Give the fraction of the total number of bytes requested by the user by the end of the trace not including calls to malloc that have subsequently been freed over total number of bytes allocated by sbrk You do not need to simplify the fraction Page 8 of 14 B Consider another malloc implementation that never calls sbrk for a size less than 32 bytes In every other way the implementation is identical to the implementation in question A Note that since no block splitting is done this means the size of each block including the header will always be at least 32 bytes Again there is no need to simplify mathematical expressions 1 After the …
View Full Document