Exam, autumn 2025
Written exam, 10 December 2025, 09:00–12:00. 27 questions. No printed or hand-written support material.
1 Temporal locality
Temporal locality refers to:
Temporal locality: the same locations are referenced again (instructions in a loop). The second option describes spatial locality.
2 Permissions in FFS
A typical Unix filesystem like FFS has permissions:
Permissions are part of the file's metadata in its inode, alongside owner and access times.
3 Interrupt
An interrupt is defined as:
4 NTFS filenames
In NTFS, the filename of a file is stored in:
5 Semaphore as a lock
A semaphore can emulate a lock under what condition?
With value 1, the first P() takes it to 0 and any further P() waits until V() is called, so only one thread is inside at a time.
6 TLB
The main purpose of a translation lookaside buffer (TLB) is to:
7 Yielding
What is meant by a thread "yielding"?
8 Running a new program
When a new program is run, the role of the operating system is:
9 Thread abstraction
What is meant by a thread abstraction?
10 Trap
A trap is defined as:
11 Least privilege
What is not an example of the principle of least privilege?
12 Round robin with equal jobs
In a round robin scheduler where all jobs have equal length, which performance metric is most negatively affected compared to first-in-first-out (FIFO) scheduling?
If tasks are equal in size, round robin has very poor average response time: every job finishes near the end.
13 Inode fields
Which one of the following fields is not contained in an inode?
The inode holds metadata such as owner, permissions and access times. The name-to-inode mapping lives in the directory, not the inode.
14 Windows and Linux process creation
What is the main difference between creating a new process in the Windows and Linux kernels?
15 Write-through cache
A write-through cache is one that:
Write-through sends changes immediately to the next level. Write-back (the second option) keeps them until the block is replaced.
16 Cooperative thread
A cooperative thread is a thread that:
17 Interrupt stack
A separate interrupt stack is required for handling interrupts because:
18 Longer time quantum
Increasing the length of the time quantum has which effect on round robin scheduling?
Fewer time slices means fewer context switches.
19 Insecure function
Consider the C code below. What is the insecure function call?
#include <stdio.h>
int main()
{
char buff[32];
gets(buff);
printf("%s", buff);
}gets copies input into the buffer without checking its length.
20 wait()
wait(), called by a parent process, is used to:
21 Order of output with condition variables
Study the following threaded and synchronised C code. The usleep(1000) ensures that thread B is always scheduled first. Put the printed lines in the correct order: Alpha 1, Alpha 2, Alpha 3, Beta 1, Beta 2, Beta 3, Ready A updated, Ready B updated.
pthread_mutex_t lock_A = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t cond_A = PTHREAD_COND_INITIALIZER;
int ready_A = 0;
pthread_mutex_t lock_B = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t cond_B = PTHREAD_COND_INITIALIZER;
int ready_B = 0;
void *thread_A(void *arg) {
printf("Alpha 1\n");
pthread_mutex_lock(&lock_A);
ready_A = 1;
printf("Ready A updated\n");
printf("Alpha 2\n");
pthread_cond_signal(&cond_A);
pthread_mutex_unlock(&lock_A);
pthread_mutex_lock(&lock_B);
while (!ready_B) {
pthread_cond_wait(&cond_B, &lock_B);
}
pthread_mutex_unlock(&lock_B);
printf("Alpha 3\n");
return NULL;
}
void *thread_B(void *arg) {
pthread_mutex_lock(&lock_A);
while (!ready_A) {
printf("Beta 1\n");
pthread_cond_wait(&cond_A, &lock_A);
}
printf("Beta 2\n");
pthread_mutex_unlock(&lock_A);
printf("Beta 3\n");
pthread_mutex_lock(&lock_B);
ready_B = 1;
printf("Ready B updated\n");
pthread_cond_signal(&cond_B);
pthread_mutex_unlock(&lock_B);
return NULL;
}
int main() {
pthread_t tA, tB;
pthread_create(&tB, NULL, thread_B, NULL);
usleep(1000);
pthread_create(&tA, NULL, thread_A, NULL);
pthread_join(tA, NULL);
pthread_join(tB, NULL);
return 0;
}Show solution
Beta 1
Alpha 1
Ready A updated
Alpha 2
Beta 2
Beta 3
Ready B updated
Alpha 3B runs first, finds ready_A == 0, prints Beta 1 and waits (releasing lock_A). A prints Alpha 1, sets ready_A, prints Ready A updated and Alpha 2, then signals. A then waits for ready_B. B wakes, prints Beta 2 and Beta 3, sets ready_B, prints Ready B updated and signals. Finally A prints Alpha 3.
22 A simple shell: fill in the blanks
Fill in the blanks so that the simple shell compiles and works. Keywords: char, execvp, return, args, 0, wait, while, printf, fork, waitpid.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/____.h>
#define MAX_LINE 80
#define TOKEN_DELIM " \t\r\n\a"
void parse_command(char *line, char **args) {
char *token;
int i = 0;
token = strtok(line, TOKEN_DELIM);
while (token != NULL) {
args[i++] = token;
token = strtok(NULL, TOKEN_DELIM);
}
args[i] = NULL;
}
int main(void) {
____ line[MAX_LINE];
char *args[MAX_LINE/2 + 1];
int status;
pid_t pid;
____ (1) {
____("simple_shell> ");
if (!fgets(line, MAX_LINE, stdin))
break;
parse_command(line, args);
if (____[0] == NULL)
continue;
pid = ____();
if (pid < 0) {
perror("Error");
exit(EXIT_FAILURE);
} else if (pid == ____) {
if (____(args[0], args) == -1) {
perror("Error");
exit(EXIT_FAILURE);
}
} else {
____(pid, &status, 0);
}
}
____ 0;
}Show solution
In order: wait (sys/wait.h), char, while, printf, args, fork, 0, execvp, waitpid, return.
This is the fork–exec–wait pattern: the child (where fork returns 0) replaces itself with the command using execvp, and the parent waits for that child with waitpid.
23 Command-line arguments
Write a C program that takes (1) a numeric argument N and (2) a string argument from the command line and prints the string N times to standard output.
$ ./myprog 3 "String"
StringStringStringShow solution
Marking: correct command-line argument handling (4 pts), conversion of the numeric argument to an integer (2 pts), correct output repetition without extra spaces or newlines (4 pts). Error checking was not required; input can be assumed valid.
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
int N = atoi(argv[1]);
for (int i=0; i<N; i++)
{
printf(argv[2]);
}
}24 Paging
A system uses paging with a page size of 256 bytes and a 20-bit virtual address space. Part of the page table (VPN = virtual page number, PFN = page frame number, PB = present bit; entries not shown have PB 0):
VPN PFN PB
15 0110 0000 0110 1
14 0001 0110 0000 1
13 0111 0111 0111 1
12 0101 1011 1011 1
11 0100 0000 1110 1
10 0000 0000 0000 0
9 0001 0010 1010 1
8 0110 0001 1111 1
7 0110 0000 1011 1
6 0100 0000 0001 1
5 0010 1110 1000 1
4 0000 0000 0000 0- How many entries does the page table have?
- How many bits is the page offset?
- What is the size of the virtual address space?
- What does the virtual address
0000 0000 1110 1010 1011translate to? - Where is the page table located?
- With a page size of 16 KB and a 36-bit virtual address space using two-level paging, how many entries are in each page table?
Show solution
- 4096. 256-byte pages need an 8-bit offset, leaving 20 − 8 = 12 bits of page number: 212 = 4096.
- 8 bits (28 = 256).
- 1 MB (220 bytes).
- 0001 0110 0000 1010 1011. The upper 12 bits
0000 0000 1110are VPN 14, which maps to PFN0001 0110 0000(present). The 8-bit offset1010 1011passes through unchanged. - RAM (internal memory).
- 2048. A 16 KB page gives a 14-bit offset, leaving 36 − 14 = 22 bits of page number, split over two levels: 11 bits each, 211 = 2048.
25 Page replacement policies
A process has 3 pages of physical memory, initially empty. Count the page faults for MIN (optimal), FIFO and LRU with the reference sequence:
A B C A D B E F A C D
Show solution
| Policy | Faults |
|---|---|
| MIN | 7 |
| FIFO | 9 |
| LRU | 10 |
MIN: A, B, C fault. A hits. D evicts C (used furthest ahead). B hits. E evicts B (never used again). F evicts E. A hits. C faults (evict A or F, neither is needed). D hits. 7 faults.
FIFO: A, B, C fault, A hits, then D evicts A, B hits, E evicts B, F evicts C, A evicts D, C evicts E, D evicts F. 9 faults.
LRU: A, B, C fault, A hits, then every remaining reference misses: D evicts B, B evicts C, E evicts A, F evicts D, A evicts B, C evicts E, D evicts F. 10 faults.
26 False sharing
Explain the concept of false sharing in the context of multicore systems (2 pts). Why does it occur (2 pts), and what impact does it have on performance (1 pt)?
Show solution
False sharing occurs when threads on different cores modify variables that sit on the same cache line, even though the variables are logically independent. Because cache coherence works at the granularity of a cache line (typically 64 bytes), any update to one variable invalidates the whole line in the other cores' caches. (2 pts)
Cache lines are the smallest unit of coherence. If two threads update different variables on one line, the hardware treats it as a conflict and the line is repeatedly invalidated and reloaded. (2 pts)
It increases memory latency and reduces scalability, because cores spend their time maintaining coherence instead of doing useful work. (1 pt)
27 Zero-on-reference and copy-on-write
- What is zero-on-reference and why is it useful? (3 pts)
- What is copy-on-write in the context of a process fork and why is it useful? (3 pts)
Show solution
- Zero-on-reference: memory pages are not physically allocated or zeroed until the process first accesses them. On the first access a page fault occurs, and the OS allocates a page and fills it with zeros. It avoids pre-zeroing large regions that may never be used, saving time and memory.
- Copy-on-write: after a fork, parent and child share the same physical pages, marked read-only. If either writes to a page, the OS traps and makes a private copy for that process. It avoids duplicating every page during fork, improving performance and saving memory.