Andrew login ID:Full Name:Section:15-213/18-243, Spring 2011Exam 2Thursday, April 21, 2011 v2Instructions:• Make sure that your exam is not missing any sheets, then write your Andrew login ID, full name, andsection 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 indicateyour 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 13Problem 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 1011 12 13 14 15 16 17 18 19 20X X X X X X X X1. 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 above3. Given an arbitrary malloc implementation that does not coalesce and a second implementation thatis identical except it does coalesce, which of the following is true about their utilization scores onan arbitrary trace? (You may assume the first implementation stores enough information to makecoalescing possible, so the only difference is that the second implementation actually performs thecoalescing.)(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 utilizationscore, 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 134. 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 avoidswalking 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 examinesonly 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) 2GB(b) 4GB(c) 8GB(d) 240TB6. Which of the following is a reason why a virtual memory translation would fault?(a) Page is not present(b) Page is read only(c) Page is empty(d) All of the above7. How many bits are needed for the Virtual Page Offset if page size is 5000 bytes?(a) 10(b) 11(c) 12(d) 138. Which of the following is preserved across exec?(a) Signal handlers(b) Blocked signals(c) a and b(d) Neither9. In what section of an ELF binary are initialized variables located?(a) .symtab(b) .data(c) .bss(d) .textPage 3 of 1310. 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, andnewfd 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 structs12. Which signals cannot be handled by the process?(a) SIGTSTP(b) SIGKILL(c) SIGTERM(d) All of the AbovePage 4 of 13Problem 2. (15 points):Process control.Consider the following code sample. You may assume that no call to fork, exec, wait, or printf willever fail, and that stdout is immediately flushed following every call to printf.int global_x = 0;int main(int argc, char*argv[]){global_x = 17;/*Assume fork never fails*/if(!fork()) {global_x++;printf("Child: %d\n", global_x);}else {wait(NULL);global_x--;printf("Parent: %d\n", global_x);}return 0;}A. What is printed by this program?B. How might the output change if we removed the call to wait? Note: Keep your answer short, youwill be penalized for excessively long answers.Page 5 of 13Now, consider the following two code samples. Again, you may assume that none of the previously men-tioned function calls can fail. You should also note that the source for my child follows the source for theinvoked program.int global_x = 0;int main(int argc, char*argv[]){global_x = 17;/*Assume fork never fails*/if(!fork()) {global_x++;/*Assume exec never fails*/execl("./my_child", "./my_child", NULL);printf("Child finished\n");}else {wait(NULL);global_x--;printf("Parent: %d\n", global_x);}return 0;}Code Listing for mychild:int global_x;int main(int argc, char*argv[]){printf("Child: %d\n", global_x);return 0;}C. Is the output for this program the same as for the previous? Why or why not? Note: Again, youranswer to this question should be short.Page 6 of 13Problem 3. (20 points):Dynamic memory allocation.In this question, we will consider the utilization score of various malloc implementations on the followingcode:#define N 32void*pointers[N];int i;for (i = 0; i < N; i++) {pointers[i] = malloc(4);}for (i = 0; i < N; i++) {free(pointers[i]);}for (i = 0; i < N; i++) {pointers[i] = malloc(56);}Page 7 of 13A. 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 multipleof 8. The header of each block stores the size of the block, and since the 3 lowest order bits areguaranteed to be 0, the lowest order bit is used to store whether the block is allocated or free. Afirst-fit allocation policy is used. If no unallocated block of a large enough size to service the requestis found, sbrk is called for the smallest multiple of 8 that can service the request. No coalescing orblock splitting is done. NOTE: You do NOT need to simplify any mathematical expressions. Yourfinal 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 fragmenta-tion and header
View Full Document