Exam, autumn 2024
Written exam, 11 December 2024, 09:00–12:00. 27 questions. A simple calculator was permitted.
1 Reliability
Which of the following is a symptom of poor reliability in an operating system?
Reliability asks whether the system does what it was designed to do. An OS that lets one program's leak affect others has failed at isolation.
2 Virtualisation
Virtualisation in the context of an operating system is defined as:
This is the OS as illusionist: each application appears to have the entire machine to itself.
3 The heap
When a process is running, the heap is used for:
4 The stack
The stack is used for:
5 Running the same program twice
In order to run multiple copies of the same program, the operating system:
The code segment is read-only and can be shared between processes. Data, heap and stack are written to, so each process needs its own.
6 Base and bound
All of the following are limitations to base and bound memory protection except:
Base and bound is safe: every access is checked against the bound. Its problems are that it cannot share memory or grow stack and heap.
7 ASLR
Address space layout randomisation is a technique used to:
8 Upcall
An upcall is:
An upcall (a UNIX signal) is user-level event delivery: the kernel notifies a user process of something that needs to be handled right away.
9 Interrupts versus polling
Interrupts are favourable compared to polling (aka busy waiting) because:
With polling the kernel waits until I/O is done; with interrupts it can do other work in the meantime.
10 Kernel philosophy
"What can be at user level, should be" is a philosophy of which type of kernel design?
11 Threads versus processes
A main benefit of using threads for concurrency over processes is:
A thread shares the address space of its process, so creating one only needs a thread control block and a stack.
12 Yielding
What is meant by a thread "yielding"?
thread_yield() relinquishes the processor voluntarily.
13 Memory barrier
A memory barrier is:
All operations before the barrier complete before it returns, and no operation after it starts until it returns.
14 Multicore synchronisation
A synchronisation problem unique to multicore systems as opposed to unicore systems is:
With several cores, many threads can try to take the same lock at the same instant, and the lock value pings between caches.
15 False sharing
False sharing is:
16 RCU writers
The read-copy-update (RCU) lock allows how many writes to happen concurrently?
Readers proceed without a lock, but the writer acquires a write lock, so only one write happens at a time.
17 Deadlock conditions
Which of the following is NOT a necessary condition for a deadlock?
The condition is no preemption. If resources can be taken away, the deadlock can be broken.
18 Segmentation
The basic idea of memory segmentation is:
19 Write permission
Which type of memory segment should not have the write access flag set in the segment table?
Segmentation can protect the code segment from being overwritten.
20 Salting
Salting with random data before hashing a password helps against:
Hashing the password with a random salt foils a precomputed password table lookup.
21 Process abstraction
Consider the following C source code. Describe what the output will be. Will the output always be the same? If yes, state why. If not, state why not.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
int main()
{
for(int i=0; i<5; i++)
{
int f = fork();
if (f > 0)
{
printf("Process %d checking in\n", i);
exit(i);
}
}
wait(NULL);
}Correction from the course: the question should have read if (f == 0), not if (f > 0). The code as written is still worth studying. Compile and run it, draw the process tree, and use strace -f ./fork to follow it. Who enters the if, how many unique parents fork a child, and which process finally calls wait(NULL)?
Show solution
The parent forks 5 children, each of which prints Process %d checking in with the loop variable i. The first forked child prints Process 0 checking in, and so on while i < 5. The parent does not print anything; it waits for the children before exiting.
Process 0 checking in
Process 1 checking in
Process 3 checking in
Process 2 checking in
Process 4 checking inBecause the kernel schedules processes unpredictably, the output will not always be the same between runs.
22 Writing numbers to a file
Write a C program that creates a new file called numbers.txt and writes the numbers 1 through 30, each on its own line, into the file. (The exam attached man pages for the libc functions.)
Show solution
Many answers are possible. The main points are that the correct calls are used (fopen, fwrite/fprintf, fclose). Partial points were given for writing to stdout with printf instead, and for having the general structure. Pseudocode was acceptable.
#include <stdio.h>
#include <stdlib.h>
// Suggested solution using fprintf
int main()
{
FILE *f = fopen("numbers.txt", "w");
for(int i=1; i<=30; i++)
{
fprintf(f, "%d\n", i);
}
fclose(f);
}23 Threading: fill in the blanks
The following C program creates 5 threads and waits for them to finish before printing their exit statuses. Fill in the blanks with the correct keywords.
Keywords to choose from: input, pthread, main, join, param, stdin, go, execve, stdio.h, NUMTHREADS, create, exit, fork, libc.h, wait.
#include <____>
#include <____.h>
#define NUMTHREADS 5
pthread_t threads[NUMTHREADS];
void *go(void *param)
{
printf("Thread %d says hello\n", (int*) ____);
pthread_____((int*)param);
}
int main()
{
for(int i=0; i<____; i++)
{
pthread_____(&threads[i], NULL, ____, (void*)i);
}
for(int i=0; i<NUMTHREADS; i++)
{
void* retval;
pthread_____(threads[i], &retval);
printf("main: thread %d returned %d\n", i, retval);
}
}Show solution
#include <stdio.h>
#include <pthread.h>
#define NUMTHREADS 5
pthread_t threads[NUMTHREADS];
void *go(void *param)
{
printf("Thread %d says hello\n", (int*) param);
pthread_exit((int*)param);
}
int main()
{
for(int i=0; i<NUMTHREADS; i++)
{
pthread_create(&threads[i], NULL, go, (void*)i);
}
for(int i=0; i<NUMTHREADS; i++)
{
void* retval;
pthread_join(threads[i], &retval);
printf("main: thread %d returned %d\n", i, retval);
}
}24 Two-level address translation
Virtual address format: 8-bit page number | 8-bit page number | 16-bit offset. Convert the virtual addresses to physical addresses using the two-level page table below, or write invalid.
| Top level | Table A | Table B |
|---|---|---|
| 0 → Page table A | 0 → 0xFEAD | 0 → 0xBEEF |
| 1 → invalid | 1 → 0xFEED | 1 → 0xFEFE |
| 2 → invalid | 2 → 0xFEEF | 2 → 0x0000 |
| 3 → Page table B | 3 → 0xCACA | 3 → 0xAEFF |
| rest invalid | rest invalid | 4 → 0x0002 |
| 5 → 0xFFAE |
- 0x0003AB05
- 0x03008080
- 0x01044140
Show solution
- 0xCACAAB05. Top index 0x00 → table A; second index 0x03 → frame 0xCACA; offset 0xAB05 passes through.
- 0xBEEF8080. Top index 0x03 → table B; second index 0x00 → 0xBEEF; offset 0x8080.
- invalid. Top index 0x01 is invalid.
25 FFS first-fit allocation
An FFS implementation with first-fit allocation accepts these commands: file /a <blocks> creates a file, dir /a creates a directory, delete /a deletes a file or directory (recursively). In the layouts below, each row is a block group: first the inodes, then the data blocks. For example file /a 3 gives:
0 /a-------- /aaa------ ---------- ----------
1 ---------- ---------- ---------- ----------1. Which three commands give this layout?
0 /ab------- /aaaabb--- ---------- ----------
1 c--------- c--------- ---------- ----------2. Which two commands then give this?
0 /abc------ /aaaabbccc ---------- ----------
1 ---------- ---------- ---------- ----------3. Which two commands then give this?
0 /abc------ /aaaabbccc ---------- ----------
1 dE-------- dEEEEEEEEE EEEEEEEEEE EEEEEEEEEEShow solution
file /a 4,file /b 2,dir /c. The directory goes into a new block group, which is how FFS spreads subdirectories.delete /c, thenfile /c 3. The file is in the root directory, so it goes into group 0 with the other files of /.dir /d, thenfile /d/E 29. The directory starts a new group, and the file inside it is placed in the same group as its directory.
The original exam had a typo in the last layout, so this part was marked manually.
26 Round robin time quantum
Discuss the tradeoffs between a short and long time quantum for a scheduling algorithm like round robin (RR).
Show solution
A short time quantum gives high responsiveness. If it is too short, each job progresses slowly and there is high overhead from frequent context switching (user → kernel and kernel → user) by the scheduler.
A long time quantum means low responsiveness, but each process gets more work done per scheduled CPU time.
27 FAT or NTFS for a camera
State the advantages and disadvantages of a FAT filesystem versus an NTFS filesystem for an embedded device such as a digital camera. Which is more appropriate for this application area?
Show solution
FAT is simple to implement and suits embedded systems where memory and processing power are restricted. A camera does not need the features of a more powerful file system such as NTFS or FFS: ownership, permissions and other metadata.
FAT advantages: simple linked-list structure, easy to find free blocks, simple implementation. FAT disadvantages: random access is slow because the linked list must be traversed, but a camera mostly appends new files. The 4 GB file size limit can be a problem for HD video (exFAT can be mentioned but is not needed). No journalling, which can lead to data loss. Fragmentation over time.
NTFS is more flexible with file size, metadata and permissions, supports journalling and addresses fragmentation by design. For an embedded device, the overhead of unused features makes it generally unsuitable. FAT is the more appropriate choice.