This is an open book, open notes exam. However, you may use only the two required textbooks: Advanced Programming in the Unix Environment and Code Complete: A Practical Handbook of Software Construction.
You have one hour and fiften minutes to complete the exam.
Your blue book must contain the problems in numerical order, with no more than one problem per page.
Statistics
Mean 66.7 Median 68 Min 33 Max 98 Std Dev 16.4
cat data.txt | sortwhere
data.txt
contains lines of text.
The stdout of the 'cat' command is redirected to the stdin of the 'sort' command via a pipe. stderr of both commands displays text to the terminal.
int a[10][20]; int *b[10];then
a[3][4]
and b[3][4]
are both
syntactically legal references to a single int
. What's the
difference between the two definitions?
The definition ofa
actually allocates storage for 10*20=200 integer elements. The definition forb
allocates 10 pointers that can point to variable-length rows. No storage is allocated for these rows; this needs to be done separately, e.g., bymalloc()
.
int *f(double *, ...); int (*g)(struct foo *);do. (E.g.,
int h(double)
is a function returning an integer
and taking a double as an argument, passing it by value.)
f
returns a pointer to an integer, based on a variable-length argument list. The first argument is a pointer to a double variable, so that the value is passed by reference.
g
is a function pointer to a function returning an integer. The function referenced byg
takes a single argument, a pointer to a structure of typefoo
.
Wheat grows from seeds. Dough is made by mixing wheat flour, water, yeast and salt. The dough is shaped by hand or a machine. The dough is then left to rise when left alone in a warm surrounding. Finally, the loaf is baked.wheat: seeds water sun sow seeds wait 4 months flour: wheat grind wheat dough: flour water yeast salt mix flour water yeast salt bread: dough rise dough bake dough
extern int p; int debug = 0; int fact(int x) { int p; if (debug) { printf("x = %d\n", x); } p = x * fact(x-1); return p; }describe where (i.e., type of memory) the variables are placed at run-time.
The global variablep
is an external global variable stored in the uninitialized data segment (assuming that the actual definition has no initial value).debug
is stored in the initialized data segment. The local variablesp
andx
are stored on the stack. (The program has the minor problem that it doesn't terminate, but that's beyond the scope of the question...)
main
function that prints a string "Still
working (t)..." to the screen every ten seconds, while the rest
of the program goes about its normal business. t is the number
of seconds that the program has been active.
In the program below, the sleeping and printing doing computation part could be replaced by any other computation. Re-setting the signal handler within the handler is required only on Solaris, not on Linux. The inclusion of signal() within handler() made no difference in grading.#include#include void handler(int sig) { printf("Still working...!\n"); signal(SIGALRM, handler); alarm(10); } int main(int argc, char *argv[]) { int i; signal(SIGALRM, handler); alarm(10); while (1) { sleep(3); printf("doing computation\n"); } return 0; }
malloc()
. You do not
have to worry about optimization, but must use pointer and pointer
arithmetic. Unlike in a real OS, you are given a large chunk of memory,
defined as
char memory[100000];
You only have to implement malloc()
, not free
or other related functions. You can assume that a free()
function exists. Your function should not run out of memory as long as
there is available space in memory
, either unallocated or
freed. You do not have to worry about fragmentation and may return a
larger chunk of memory than is necessary.
malloc.c
A cvs checkin conflict occurs if two or more developers edit the same source file in roughly the same place. cvs cannot decide which of the changes should take precedence. The checkin conflict is flagged when the second person tries to check in the changes. There are several complementary ways to avoid or minimize this problem:
- Frequent
cvs update
to make sure that one is working with the most recent version.- Use of
cvs watch
andcvs edit
to alert other developers in the group that one is working on a particular file.