Andrew login ID Full Name Section 15 213 18 243 Fall 2010 Exam 2 Tuesday November 9 2010 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 closed notes although you may use a single 8 1 2 x 11 sheet of paper with your own notes You may not use any electronic devices 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 67 points The problems are of varying difficulty The point value of each problem is indicated Good luck 1 10 2 06 3 12 4 09 5 09 6 12 7 09 TOTAL 67 Page 1 of 15 Problem 1 10 points Multiple choice on a variety of topics Write the correct answer for each question in the following table 1 2 3 4 5 6 7 8 9 10 1 For the Unix linker which of the following accurately describes the difference between global symbols and local symbols a There is no functional difference as to how they can be used or how they are declared b Global symbols can be referenced by other modules files but local symbols can only be referenced by the module that defines them c Global symbols refer to variables that are stored in data or bss while local symbols refer to variables that are stored on the stack d Both global and local symbols can be accessed from external modules but local symbols are declared with the static keyword 2 Consider the following C variable declaration int f 3 Then f is a an array of pointers to pointers to functions that return int b a pointer to an array of functions that return pointers to int c a function that returns a pointer to an array of pointers to int d an array of pointers to functions that return pointers to int e a pointer to a function that returns an array of pointers to int f a pointer to an array of pointers to functions that return int Hint Recall from the K R book that and have higher precedence than 3 Which of the following is true concerning dynamic memory allocation a External fragmentation is caused by chunks which are marked as allocated but actually cannot being used b Internal fragmentation is caused by padding for alignment purposes and by overhead to maintain the heap data structure such as headers and footers c Coalescing while traversing the list during calls to malloc is known as immediate coalescing d Garbage collection employed by calloc refers to the practice of zeroing memory before use Page 2 of 15 For the next 3 questions consider the following code running on a 32 bit Linux system Recall that calloc zeros the memory that it allocates int main long a b c char p p calloc 8 sizeof char calloc returns 0x1dce1000 a long p 0x100 b long p 0x200 c int b 0x300 printf p p a x b p c x n p a b c exit 0 4 When printf is called what is the hex value of variable a a Can t tell b 0x1dce1100 c 0x1dce1400 d 0x1dce1800 5 When printf is called what is the hex value of variable b a Can t tell b 0x1dce1200 c 0x1dce2000 d 0x200 e 0x800 6 When printf is called what is the hex value of variable c a Can t tell b 0x1dce2a00 c 0x1dce4400 d 0xc00 e 0xe00 Page 3 of 15 7 Which of the following is not a default action for any signal type a The process terminates b The process reaps the zombies in the waitlist c The process stops until restarted by a SIGCONT signal d The process ignores the signal e The process terminates and dumps core 8 A system uses a two way set associative cache with 16 sets and 64 byte blocks Which set does the byte with the address 0xdeadbeef map to a Set 7 b Set 11 c Set 13 d Set 14 9 When it succeeds execve is called once and returns how many times a 0 b 1 c 2 d 3 10 When it suceeds fork is called once and returns how many times a 0 b 1 c 2 d 3 Page 4 of 15 Problem 2 6 points Linking Consider the executable object file a out which is compiled and linked using the command unix gcc o a out main c foo c and where the files main c and foo c consist of the following code main c include stdio h foo c int a b c static int a 1 int b 2 int c void foo a 4 b 5 c 6 int main int c 3 foo printf a d b d c d n a b c return 0 What is the output of a out Answer a b c Page 5 of 15 Problem 3 12 points Cache Operation In this problem you are asked to simulate the operation of a cache You can make the following assumptions There is only one level of cache Physical addresses are 8 bits long m 8 The block size is 4 bytes B 4 The cache has 4 sets S 4 The cache is direct mapped E 1 a What is the total capacity of the cache in number of data bytes b How long is a tag in number of bits c Assuming that the cache starts clean all lines invalid please fill in the following tables describing what happens with each operation Addresses are given in both hex and binary for your convenience Operation load 0x00 0000 0000 2 load 0x04 0000 0100 2 load 0x08 0000 1000 2 store 0x12 0001 0010 2 load 0x16 0001 0110 2 store 0x06 0000 0110 2 load 0x18 0001 1000 2 load 0x20 0010 0000 2 store 0x1A 0001 1010 2 Set index 0 0 2 Page 6 of 15 Hit or Miss miss miss Eviction no Problem 4 9 points Signals Consider the following three different snippets of C code Assume that all functions and procedures return correctly and that all variables are declared and initialized properly Also assume that an arbitrary number of SIGINT signals and only SIGINT signals can be sent to the code snippets randomly from some external source For each code snippet circle the value s of i that could possibly be printed by the printf command at the end of each program Careful There may be more than one correct answer for each question Circle all the answers that could be correct Code Snippet 1 Code Snippet 2 Code Snippet 3 int i 0 int i 0 int i 0 void handler int sig i 0 void handler int sig i 0 void handler int sig i 0 sleep 1 int main int j int main int j sigset t s signal SIGINT handler for j 0 j 100 j i sleep 1 printf i d …
View Full Document