Operating Systems
Final exam (solution)
Academic year 2023-2024
_____________________________________________________________________________
Name and surname: ______________________________ NIU:____________________
Laboratory 3 - Validation test
Answers
1 2 3 4 5 6
A D B C B D
Answer the following multiple-choice questions in the space at the top of the page using CAPITAL
letters. Correctly answered questions add 0.5 points, incorrectly answered or unanswered questions
neither add nor subtract (0 points). For each question there is only one correct answer.
Question 1
If we have allocated dynamic memory using the following code:
uint16_t buffer_size = buffer_elements * sizeof(char);
char* buffer_ptr = malloc(buffer_size);
What is the proper way to free the dynamic memory once we have finished using it?
A) free(buffer_ptr); B) free(*buffer_ptr);
C) free(&buffer_ptr); D) dealloc(buffer_ptr);
Question 2
What is the proper system call to print a message containing “Error!” to the standard error output?
A) printf(1, “Error!”); B) printf(2, “Error!”);
C) fprintf(1, “Error!”); D) fprintf(2, “Error!”);
Question 3
What is the correct system call to wait for a thread to finish executing?
A) pthread_wait() B) pthread_join()
C) thread_wait() D) thread_join()
Question 4
When a user presses the CTRL+C combination, what is the interrupt that the operating system sends
to the program currently running and that can be captured calling the signal() system call?
A) SIGHUP B) SIGKILL
C) SIGINT D) SIGSEGV
Question 5
We have the following structure definition and declaration:
typedef struct {
ring_buffer_t* rb;
pthread_mutex_t m;
} thread_data_t;
thread_data_t td;
What is the proper way to initialize the mutex contained in the td variable of type thread_data_t?
A) pmutex_init(&td.m, NULL) B) pthread_mutex_init(&td.m, NULL)
C) pmutex_init(td.m, NULL) D) pthread_mutex_init(td.m, NULL)
Question 6
If we have function with the following prototype:
void* throw_dart(void* args);
How can you create a thread that executes the throw_dart function when it is created, and pass to it a
variable named data in the args argument?
A) pthread_create(&thread_array[i], NULL, B) pthread_create(&thread_array[i], NULL,
throw_dart, data); throw_dart, &data);
C) pthread_create(&thread_array[i], NULL, D) pthread_create(&thread_array[i], NULL,
&throw_dart, data); &throw_dart, &data);
Page 1 of 2
Operating Systems
Final exam (solution)
Academic year 2023-2024
_____________________________________________________________________________
Laboratory 4 - Validation test
Answers
1 2 3 4 5 6
A C B B D A
Answer the following multiple-choice questions in the space at the top of the page using
CAPITAL letters. Correctly answered questions add 0.5 points, incorrectly answered or
unanswered questions neither add nor subtract (0 points). For each question there is only one
correct answer.
Question 1
What is the correct way to convert an ASCII character that contains a number (i.e., between 0 and 9)
stored in a variable named val of type char into its numerical value, and store it in a variable named
num of type uint8_t?
A) uint8_t num = val – ‘0’ B) uint8_t num = val + ‘9’
C) uint8_t num = val – ‘a’ D) uint8_t num = val – ‘A’
Question 2
In UNIX, what is the character that represents the end of a line?
A) ‘\r\n’ B) ‘\r’
C) ‘\n’ D) ‘\0’
Question 3
What is the functionality implemented by the inet_pton() function?
A) Convert an IP address from binary to a string B) Convert an IP address from string to binary
C) Create a stream-oriented socket with the IP D) Check that an IP address in string form is valid
passed as parameter
Question 4
What happens with the requests to the QOTD server if the socket is not properly closed after each
request?
A) None of the requests is served. B) The first request is served correctly, but the
following ones are not served.
C) The first request is served correctly, but the D) All the requests are served correctly and the
following ones depend on the status of the server. socket can be closed at the end of the program.
Question 5
After creating the socket with the socket() system call and connecting it with the connect() system call,
how can you receive a block of 512 bytes of data into a variable named buf from the QOTD server?
Assume that the socket() system call has returned a value of 3.
A) recv(3, buf, 512, NULL); B) recvfrom(3, buf, 512, NULL, NULL);
C) read(3, buf, 512); D) Both A) and C) answers are valid.
Question 6
What is the port of the QOTD service and how can you ensure that its value is correct regardless of the
endianness of your computer? You can assume that a variable of type struct sockaddr_in has been
declared with name servaddr.
A) servaddr.sin_port = htons(17); B) servaddr.sin_port = 17;
C) servaddr.sin_port = ntohs(17); D) servaddr.in_address = 17;
Page 2 of 2