CS360 Final Exam - May 6, 2013 - James S. Plank

Answer all questions on the answer sheets. When you write code, you do not need to include any include files. I would prefer, if you have time, that you rewrite your code to make it neat.

If you find that you cannot write code, either because you don't have time or you don't know how, then write me pseudo-code telling me what you think you should do. You won't get more than half credit, but at least you'll get something.


Question 1

Write the program telnet which takes two command line arguments -- a host and a port, and provides a generic text-based client to a server. (By this point, you should know what telnet does). Use the standard I/O library instead of the read()/write() system calls.

You don't have error check the command line.


Question 2

Suppose that memory is allocated as described in the lecture notes: You are deep inside your program, and you've made the following sequence of calls:

a = malloc(14);
b = malloc(32);
c = malloc(55);
free(a)
d = malloc(50);

printf("a = 0x%x\n", (unsigned long) a);
printf("b = 0x%x\n", (unsigned long) b);
printf("c = 0x%x\n", (unsigned long) c);
printf("d = 0x%x\n", (unsigned long) d);

When your program reaches the code above, it prints:

a = 0x10470
b = 0x104f0
c = 0x10488
d = 0x10530

On the answer sheet, I have memory addresses 0x10430 to 0x1058c. I would like you to fill in the free list information and the bookkeeping information stored by malloc() after the last printf() statement subject to the following constraints:

You only need to fill in the memory addresses that store free list information and bookkeeping information from malloc(). Leave the rest of the memory addresses blank.