Exam, autumn 2025

Written exam, 10 December 2025, 09:00–12:00. 27 questions. No printed or hand-written support material.

Jump to a question
  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27

1 Temporal locality

2 marksRead: Caching and virtual memory

Temporal locality refers to:

2 Permissions in FFS

2 marksRead: Storage and file systems

A typical Unix filesystem like FFS has permissions:

3 Interrupt

2 marksRead: The kernel abstraction

An interrupt is defined as:

4 NTFS filenames

2 marksRead: Storage and file systems

In NTFS, the filename of a file is stored in:

5 Semaphore as a lock

2 marksRead: Synchronisation

A semaphore can emulate a lock under what condition?

6 TLB

2 marksRead: Address translation

The main purpose of a translation lookaside buffer (TLB) is to:

7 Yielding

2 marksRead: Concurrency and threads

What is meant by a thread "yielding"?

8 Running a new program

2 marksRead: The programming interface

When a new program is run, the role of the operating system is:

9 Thread abstraction

2 marksRead: Concurrency and threads

What is meant by a thread abstraction?

10 Trap

2 marksRead: The kernel abstraction

A trap is defined as:

11 Least privilege

2 marksRead: Security

What is not an example of the principle of least privilege?

12 Round robin with equal jobs

2 marksRead: Scheduling

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?

13 Inode fields

2 marksRead: Storage and file systems

Which one of the following fields is not contained in an inode?

14 Windows and Linux process creation

2 marksRead: The programming interface

What is the main difference between creating a new process in the Windows and Linux kernels?

15 Write-through cache

2 marksRead: Caching and virtual memory

A write-through cache is one that:

16 Cooperative thread

2 marksRead: Concurrency and threads

A cooperative thread is a thread that:

17 Interrupt stack

2 marksRead: The kernel abstraction

A separate interrupt stack is required for handling interrupts because:

18 Longer time quantum

1 marksRead: Scheduling

Increasing the length of the time quantum has which effect on round robin scheduling?

19 Insecure function

2 marksRead: Security

Consider the C code below. What is the insecure function call?

#include <stdio.h>
int main()
{
    char buff[32];
    gets(buff);
    printf("%s", buff);
}

20 wait()

2 marksRead: The programming interface

wait(), called by a parent process, is used to:

21 Order of output with condition variables

8 marksRead: Synchronisation

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 3

B 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

10 marksRead: The programming interface

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

10 marksRead: C for the exam

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"
StringStringString
Show 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

12 marksRead: Address translation

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
  1. How many entries does the page table have?
  2. How many bits is the page offset?
  3. What is the size of the virtual address space?
  4. What does the virtual address 0000 0000 1110 1010 1011 translate to?
  5. Where is the page table located?
  6. 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
  1. 4096. 256-byte pages need an 8-bit offset, leaving 20 − 8 = 12 bits of page number: 212 = 4096.
  2. 8 bits (28 = 256).
  3. 1 MB (220 bytes).
  4. 0001 0110 0000 1010 1011. The upper 12 bits 0000 0000 1110 are VPN 14, which maps to PFN 0001 0110 0000 (present). The 8-bit offset 1010 1011 passes through unchanged.
  5. RAM (internal memory).
  6. 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

9 marksRead: Caching and virtual memory

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
PolicyFaults
MIN7
FIFO9
LRU10

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

5 marksRead: Multi-object synchronisation and deadlock

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

6 marksRead: Caching and virtual memory Address translation

  1. What is zero-on-reference and why is it useful? (3 pts)
  2. What is copy-on-write in the context of a process fork and why is it useful? (3 pts)
Show solution
  1. 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.
  2. 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.