CS 0449 – Sample Final Exam

 

1.)           Which of the following attempts to guarantee the order and receipt of packets on a network?

                A)  IP

                B)  DNS

                C)  UDP

                D)  TCP

2.)           Which of these is not a synchronization primitive?

                A)  Padlock

                B)  Semaphore

                C)  Condition Variable

                D) Mutex

 

3.)           How does make know what files to rebuild when you run it?

                A) By checking the last-modified timestamps of the files              

                B)  By examining the Makefile for the dependency information

                C)  By checking the contents of the file for changes

                D) A and B 

                E)  B and C

 

4.)  (4 points) Of the following Berkley Socket functions, place the ones necessary to produce a working client in the order they should be executed

accept

bind

connect

listen

socket

 

 

5.) What are the possible valid outputs of the following program:

#include <stdio.h>

#include <unistd.h>

 

int main()

{

    if(fork()==0)

    {

        printf("Hi from the child!\n");

    }

    else

    {

        printf("Hi from the parent\n");

    }

 

    printf("Hi from both\n");

    return 0;

}

 

 

 

 

 

6.) (10 points) What does the keyword “static” mean when applied to a variable? (There are two answers, provide both.)

 

 

 

 

 

 

 

 

 

 

7.) (10 points) Examine the following code implementing an unrealistically simple queue:

 

#define MAX 100

int queue[MAX];

int tail=0;

int head=0;

 

void enqueue(int x)

{

       queue[tail++] = x;

}

 

int dequeue()

{

       return queue[head++];

}

 

a.)    Explain how a race condition might occur

 

 

 

 

b.)    How would you fix it?

 

 

 

 

8.) Draw a diagram that describes how the pi_digits program was able to read from /dev/pi. Make sure you include the program, the driver, the OS kernel, /dev/pi, and the system calls involved.