Andrew login ID:Full Name:Section:15-213/18-243, Spring 2011Exam 2Thursday, April 21, 2011 v1Instructions:• 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 14Problem 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 144. 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 1410. 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 14Problem 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 bac bca cab cbaPage 5 of 14B. 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 14Problem 3. (20 points):Dynamic memory allocation.In this question, we will consider the utilization score of various malloc implementations on the followingcode:#define N 64void*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 14A. 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 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 bytesallocated by sbrk. You do not need to simplify the fraction.Page 8 of 14B. Consider another malloc implementation that never calls sbrk for a size less than 32 bytes. In everyother way the implementation is identical to the implementation in question A. Note that since noblock splitting is done, this means the size of each block, including the header, will always be at least32 bytes. Again, there is no need to simplify
View Full Document