Exam, autumn 2024

Written exam, 11 December 2024, 09:00–12:00. 27 questions. A simple calculator was permitted.

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 Reliability

2 marksRead: What an operating system is

Which of the following is a symptom of poor reliability in an operating system?

2 Virtualisation

2 marksRead: What an operating system is

Virtualisation in the context of an operating system is defined as:

3 The heap

2 marksRead: Address translation

When a process is running, the heap is used for:

4 The stack

2 marksRead: Address translation

The stack is used for:

5 Running the same program twice

2 marksRead: Address translation

In order to run multiple copies of the same program, the operating system:

6 Base and bound

2 marksRead: Address translation

All of the following are limitations to base and bound memory protection except:

7 ASLR

2 marksRead: Security Address translation

Address space layout randomisation is a technique used to:

8 Upcall

2 marksRead: The kernel abstraction

An upcall is:

9 Interrupts versus polling

2 marksRead: The kernel abstraction

Interrupts are favourable compared to polling (aka busy waiting) because:

10 Kernel philosophy

2 marksRead: The kernel abstraction

"What can be at user level, should be" is a philosophy of which type of kernel design?

11 Threads versus processes

2 marksRead: Concurrency and threads

A main benefit of using threads for concurrency over processes is:

12 Yielding

2 marksRead: Concurrency and threads

What is meant by a thread "yielding"?

13 Memory barrier

2 marksRead: Synchronisation

A memory barrier is:

14 Multicore synchronisation

2 marksRead: Multi-object synchronisation and deadlock

A synchronisation problem unique to multicore systems as opposed to unicore systems is:

15 False sharing

2 marksRead: Multi-object synchronisation and deadlock

False sharing is:

16 RCU writers

2 marksRead: Multi-object synchronisation and deadlock

The read-copy-update (RCU) lock allows how many writes to happen concurrently?

17 Deadlock conditions

2 marksRead: Multi-object synchronisation and deadlock

Which of the following is NOT a necessary condition for a deadlock?

18 Segmentation

2 marksRead: Address translation

The basic idea of memory segmentation is:

19 Write permission

2 marksRead: Address translation

Which type of memory segment should not have the write access flag set in the segment table?

20 Salting

2 marksRead: Security

Salting with random data before hashing a password helps against:

21 Process abstraction

10 marksRead: The programming interface

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 in

Because the kernel schedules processes unpredictably, the output will not always be the same between runs.

22 Writing numbers to a file

10 marksRead: C for the exam The programming interface

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

16 marksRead: Concurrency and threads

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

9 marksRead: 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 levelTable ATable B
0 → Page table A0 → 0xFEAD0 → 0xBEEF
1 → invalid1 → 0xFEED1 → 0xFEFE
2 → invalid2 → 0xFEEF2 → 0x0000
3 → Page table B3 → 0xCACA3 → 0xAEFF
rest invalidrest invalid4 → 0x0002
5 → 0xFFAE
  1. 0x0003AB05
  2. 0x03008080
  3. 0x01044140
Show solution
  1. 0xCACAAB05. Top index 0x00 → table A; second index 0x03 → frame 0xCACA; offset 0xAB05 passes through.
  2. 0xBEEF8080. Top index 0x03 → table B; second index 0x00 → 0xBEEF; offset 0x8080.
  3. invalid. Top index 0x01 is invalid.

25 FFS first-fit allocation

7 marksRead: Storage and file systems

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 EEEEEEEEEE
Show solution
  1. file /a 4, file /b 2, dir /c. The directory goes into a new block group, which is how FFS spreads subdirectories.
  2. delete /c, then file /c 3. The file is in the root directory, so it goes into group 0 with the other files of /.
  3. dir /d, then file /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

4 marksRead: Scheduling

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

4 marksRead: Storage and file systems

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.