CS361 Computer Systems - PRACTICE Final: The Exam Has 4 Questions, For A Total of 101 Points
CS361 Computer Systems - PRACTICE Final: The Exam Has 4 Questions, For A Total of 101 Points
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:
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?
b. simple segregated
c. segregated fits
(b) (3 points) We fork a process. The parent process and its child will NOT share:
(c) (3 points) Which network layer do TCP and UDP belong to?
(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.
(g) (3 points) The mark and sweep algorithm frees memory if there is not:
(h) (3 points) Calling open on a string representing a file path will return:
a. a file descriptor.
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?
c. It is not technically possible to work with files without a separate open call.
a. everything is okay.
a. a set of sockets.
(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:
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);
}
(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++;
}
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;
}
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;
int x = (int)(*arg);
reserveseat(x);
observer++;
get_seat_map()
observer--;