CS361 Computer Systems - PRACTICE Final: The Exam Has 4 Questions, For A Total of 101 Points

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

CS361 Computer Systems - PRACTICE Final

The exam has 4 questions, for a total of 101 points.

Question: 1 2 3 4 Total
Points: 16 42 15 28 101
Score:
CS 361 Practice Final Name:

1. True/False. For statement below, circle T for True or F for False.


(a) (16 points) True/False. For each statement below, circle T for True or F for False. Each statement
is worth 1 point.

T F Fork will never return.

T F Physical memory is usually larger that virtual memory.

T F A process is guaranteed to receive all signals sent to it.

T F Modern operating systems use deadlock detection to avoid deadlocked programs.

T F Adding more threads will always make programs faster.

T F A race condition is when running instructions in different orders


in different threads will change the outcome of a piece of code.

T F Mutual exclusion is a necessary condition for deadlock.

T F Programs are compiled using the physical addresses of where variables will be
at runtime.

2. Multiple choice. Circle the letter which corresponds to the correct answer. Circle exactly one letter
unless the question states otherwise.
(a) (3 points) In which free list system are all blocks in a free list the same size?

a. implicit free list

b. simple segregated

c. segregated fits

d. the buddy system

(b) (3 points) We fork a process. The parent process and its child will NOT share:

a. a file descriptor table.

b. entries in the open file table.

c. entries in the v-node table.

Points earned: out of a possible 0 points


CS 361 Practice Final Name:

(c) (3 points) Which network layer do TCP and UDP belong to?

a. The link layer

b. The network layer

c. The transport layer

d. The application layer

(d) (3 points) Assume you are setting up a server. To attach a socket to a specific port, you call:

a. bind.

b. connect.

c. listen.

(e) (3 points) Which of the following can never be made thread-safe?

a. Functions with only local variables

b. Functions which hold state in static variables

c. Functions which use global variables

(f) (3 points) If the valid bit is zero in a page table entry:

a. the memory address is invalid.

b. the page is not in memory.

c. the page has not been used recently.

(g) (3 points) The mark and sweep algorithm frees memory if there is not:

a. a direct pointer to it from the stack or globals.

b. a direct pointer to it from the heap.

c. a chain of pointers to it originating in either the stack or globals.

Points earned: out of a possible 0 points


CS 361 Practice Final Name:

(h) (3 points) Calling open on a string representing a file path will return:

a. a file descriptor.

b. a number of bytes read.

c. 0 on success, -1 on errors.

(i) (3 points) We call read or write on file descriptors. Why dont we just call read or write on a file
path string?

a. This is more efficient

b. This is more secure

c. It is not technically possible to work with files without a separate open call.

(j) (3 points) The HTTP code 200 indicates:

a. everything is okay.

b. the file was not found.

c. the file has permanently moved.

(k) (3 points) An fd set is:

a. a set of sockets.

b. a set if file descriptors.

c. a bit vector corresponding to file descriptors.

Points earned: out of a possible 0 points


CS 361 Practice Final Name:

(l) (3 points) If two pieces of code are run alternating instructions from each piece of code, we refer to
this as:

a. concurrent.

b. parallel.

(m) (3 points) A process has a socket open. It forks a child. We must close the socket in:

a. the child process.

b. the parent process.

c. both.

d. either.

(n) (3 points) Thread1 has a socket open. It creates another thread (Thread2). We must close the
socket in:

a. Thread2.

b. Thread1

c. both.

d. either.

3. Short Answer
(a) (5 points) What values will be in x and y after this code runs?
int main(){
pthread_t tid;
int x = 3;
int *y;
Pthread_create(&tid, NULL, thread, &x);
Pthread_join(tid, &y);
}

void *thread(void *vargp){


*((int *)vargp) = *((int *)vargp) + 1;
return vargp;
}

Points earned: out of a possible 0 points


CS 361 Practice Final Name:

(b) (5 points) Where is the value that the created thread is printing?
Void *thread1(){
int x = 8;
thread_t tid;
Pthread_create(&tid,NULL,thread2,&x);
x++;
}

void *thread2(void *vargs){


printf(?%d\n?,*((int *)x);
}

(c) (5 points) Will this program ever finish?


int counter = 0;

void myHandler2(int sig) {


counter++;
printf("%d ", counter);
if (counter == 2) exit(0);
}

int main() {
signal(SIGUSR1, myHandler2);
printf("%d ", counter);
if ((pid = fork()) == 0) {
while(1) {};
}
kill(pid, SIGUSR1);
kill(pid, SIGUSR1);
waitpid(pid, NULL, 0);
return 0;
}

Points earned: out of a possible 0 points


CS 361 Practice Final Name:

4. Imagine we are implementing a system that reserves seats on airplanes. We want only one person to
be able to reserve a seat at a time, but many people to be able to look at which seats are available
when no one is currently reserving a seat. (I.e. we want either one reserver or any number of observers
to be able to interact with our airline seat database at a given time.) Assume that reserveseat(int x)
reserves a given seat, and get seat map() allows observers to see which seats are currently available.
Add synchronization code to the code below using pthread mutexes. You can add logical statements (if
statements, for loops, etc) and variables as well as mutex lock and mutex unlock statements. Add any
shared variables to the shared memory section. Assume any mutexes will be initialized properly.
(a) (3 points) Shared Memory

int observer;

(b) (10 points) Reserver


void reserver(void *arg){

int x = (int)(*arg);

reserveseat(x);

Points earned: out of a possible 0 points


CS 361 Practice Final Name:

(c) (15 points) Observer


void observer(){

observer++;

get_seat_map()

observer--;

Points earned: out of a possible 0 points

You might also like