Question 1: Which of the following operations
are likely to require performing at least one system call on an operating
system with a monolithic kernel design like xv6?
Select all that apply
Question 2: Suppose an xv6 system is running two processes. Process A starts to read from the keyboard, and while it is waiting for input from the keyboard, xv6 context switches and starts running process B in user mode. Then, a key is pressed and the corresponding interrupt happens. Where will process B's registers be saved while the interrupt is happening?
Question 3: Unix-like operating systems like xv6 provide programs access to I/O devices, like keyboards and monitors, primarily through the abstraction of
Question 1 (0 points): Consider the following POSIX C program:
int main() {
for (int i = 0; i < 3; i += 1) {
pid_t p = fork();
if (p == 0) {
i += 1;
}
printf("%d", i);
fflush(stdout);
}
}
Assuming fork()
, printf()
, and fflush()
do not fail, which
of the following are possible outputs?
Select all that apply
Question 2: On a typical implementation of POSIX, when an application performs
a library call like read(fd, buffer, 16)
to read from the keyboard, _____.
Select all that apply
Question 3: Which of the following are true about a call to waitpid like waitpid(pid, &status, 0)
?
Select all that apply
Question 4: Consider the following POSIX C program firstkilobyte
:
#include <unistd.h>
int main(void) {
char buffer[1024];
ssize_t amount_read = read(STDIN_FILENO, buffer, 1024);
if (amount_read > 0) {
write(STDOUT_FILENO, buffer, amount_read);
}
}
This program attempts to read the first up to 1 kilobyte from its input and send it to its output. When run like
firstkilobyte <input.dat >output.dat`
the program always seems to work correctly, but when run as part of a shell pipeline like
./some_other_program | ./firstkilobyte > output.dat
sometimes it outputs less than the first kilobyte. Which of
the following is a possible explanation for this?
Select all that apply
Question 1: Which changes to a system are likely to improve a
system's throughput?
Select all that apply
Question 2: In lecture, we discussed multi-level feedback queue schedulers that attempts to adjust a process's priority
based on the length of its CPU bursts.
In such a scheduler, programs at the highest priority
Select all that apply
Consider a operating system running whose ready queue contains three processes: * process A, which needs to run for 5 units of time * process B, which needs to run for 15 units of time, and * process C, which needs to run for 10 units of time Assume the processes are in sorted in that order in the queue, so A is the first process in the queue. After a process completes its unit of time, it will not become ready again (for the purposes of these questions). For all these questions, you may ignore context switch and other overheads.
Question 3: (see above) What will the mean turnaround time be if this system uses a first-come, first-served scheduler?
Question 4: (see above) What will the mean turnaround time be if this system uses a round-robin scheduler which enforces a 6 unit time quantum? (You may assume the system enforces the time quantum by starting a timer just before it switches to the process.)
Question 1: In Linux's Completely Fair Scheduler (CFS), when a process becomes runnable after not
having been runnable for some time, if it's virtual time is too low compared to
other programs, it is increased. To decide whether the virtual time is "too low",
the scheduler has a maximum amount of difference that is allowed between the newly
runnable program's virtual time and the "current" virtual time. Increasing this
limit (allowed difference) will generally
Select all that apply
Question 2: Some schedulers are susceptible to starvation where, given some mixes of
running programs, some of those programs will never be run no matter
how long they wait. Which are examples of schedulers with this property?
Select all that apply
Question 3: On a system which implements kernel threads, creating a new thread would
require allocating
Select all that apply
Question 4: Consider the following code snippet:
void *bar(void *arg) {
int *q = (int*) arg;
...
}
int foo() {
pthread_t;
int value = 42;
int *p = &value;
pthread_create(&t, NULL, bar, (void*) p);
pthread_join(t, NULL);
return value;
}
Assume that the pthread_create
and pthread_join
calls is successful.
What is true abou the above code?
Select all that apply
Question 1: In lecture, we discussed a way to implement a mutex lock using a spinlock and a queue of waiting threads. In this design, threads is added to queue
In lecture we discussed a cache coherency mechanism where
For the below questions, assume that values are only evicted from each processor's cache because cache coherency requires it (that is, never because the cache runs out of room) and that values are cached whenever possible.
Question 2: (see above) Suppose two processors A and B share a value X in memory. Initially, both processors do not have X cached. Then, they execute the following accesses in the following order:
How many times is processor A's cached copy of X
updated or invalidated?
Question 3: (see above) Two processors can simulatenously
Select all that apply
Question 4: Suppose we are writing a multithreaded program where some threads are responsible for computing graphs and other threads are responsible for displaying them. We want the graph displaying threads to wait until a graph has been computed before it starts trying to display a graph. To implement this waiting using a counting semaphore, we could initialize the sempahore to _________, use the ______ operation after a thread computes a graph, and use the ________ operation before a thread displays a graph.
Suppose we have a variant of producer/consumer where there are two produce functions:
and one Consume(int *pointerLeft, int *pointerRight)
function which waits for a left and right value to be
available, returning when one isthey are [edited 2019-02-24]. An incomplete implemation (with missing code marked
with _____
s) of these functions appears as
follows:
pthread_mutex_lock_t lock;
pthread_cond_t ready_cv;
Queue queueLeft;
Queue queueRight;
void ProduceLeft(int value) {
pthread_mutex_lock(&lock);
queueLeft.enqueue(value);
pthread_cond_signal(&ready_cv);
pthread_mutex_unlock(&lock);
}
void ProduceRight(int value) {
pthread_mutex_lock(&lock);
queueRight.enqueue(value);
pthread_cond_signal(&ready_cv);
pthread_mutex_unlock(&lock);
}
void Consume(int *pointerLeft, int *pointerRight) {
pthread_mutex_lock(&lock);
___________________________ // (A)
*pointerLeft = queueLeft.dequeue();
*pointerRight = queueRight.dequeue();
pthread_mutex_unlock(&lock);
}
Question 1: (see above) Which of the following could go in the blank marked (A)
and result in correct
implementation?
Select all that apply
Question 2: (see above) Which of the following could replace the pthread_cond_signal(&ready_cv)
in ProduceLeft
and result in a correct implementation?
Select all that apply
Consider one is implementing a plane ticketing system where each plane flight is represented by a data structure which has a lock and a list of reservations on that flight. To reserve a plane ticket for a user-supplied list of multiple flights, the system iterates through the list and acquires the lock for each flight, then iterates through the list and verifies seats are available on each flight, then iterates through the list and modifies the list of reservations for each flight, then releases the locks for all the flights.
Question 3: (see above) When might the above strategy result in deadlocks?
Select all that apply
Question 4: (see above) What strategies would prevent the flight reserving function from deadlocking?
Select all that apply
Question 1: Suppose an xv6 system has a page table base pointer that is set to point to
physical page 0x123
, or physical byte address 0x123000
. Recall that
xv6 runs with a two-level page table, where page tables at each
level contain 1024 4-byte page table entries.
What is the physical byte address of the first-level page table entry that the processor
will access when accessing virtual address 0x555555
?
Question 2: xv6 contains a userspace malloc()
function which is implemented in terms of the
sbrk()
system call. When an xv6 program uses malloc()
, the kernel tracks
Select all that apply
Question 3: Consider the following POSIX C code:
int fd = open("example.dat", O_RDONLY);
char *ptr = (char *) mmap(0, 16 * 1024, PROT_READ | PROT_WRITE, MAP_SHARED);
unsigned sum = 0;
for (int i = 0; i < 16 * 1024; i += 1) {
sum += ptr[i];
}
printf("%d\n", sum);
On an operating system with 4KB pages [edited 2019-03-05: word "pages" previously omitted] that implements mmap
by only setting page table entries when required
by a page fault, how many page faults will occur when executing the for
loop above?
Question 4: Consider the following C program:
int fd = open("example.dat", O_RDONLY);
char *ptr = (char *) mmap(0, 16 * 1024, PROT_READ | PROT_WRITE, MAP_PRIVATE);
ptr[1] = 'X';
printf("%c %d\n", ptr[1], sum);
exit(0);
On an operating system that uses 4KB pages, 32-bit pointers, and copy-on-write as part of its
mmap
implementation,
how many bytes must be copied by the operating system in order to implement the assignment
to ptr
above?
Question 1: Consider a system which uses 4 physical pages for its page cache and is running exactly one program that uses it (and nothing else uses the page cache). The page cache initially contains virtual pages A, B, C, and D (each assigned to a physical page). Then the program access virtual pages in the following sequence:
A, B, C, B, C, D, C, D, E, A
If the system uses a least recently used replacement policy, what is the contents of the page cache after the access pattern completes?
Consider a system which uses 6 physical pages for its page cache and is running exactly one program that uses it (and nothing else uses the page cache). Suppose the system uses the "SEQ" replacement policy we discussed in lecture and initially the inactive list contains:
and the active list contains (in order):
(and other virtual pages are not cached in a physical page).
The system temporarily marks pages on the inactive list as not present, so whenever an access to them is attempted, it immediately moves them to the active list. Whenever, the inactive list's size would go below 2 pages, the system fills the inactive list up to 2 pages.
Suppose the program accesses virtual pages in the following sequence:
C, D, G, C, D, B, H
Question 2: (see above) During the first access to G
, what page will be replaced?
Question 3: (see above) During the first access to H
, what page will be replaced?
Question 4: Which are examples of access patterns for which a least-recently used policy
page replacement performs poorly?
Select all that apply
Question 1: Suppose a keyboard controller is connected to a processor via its memory bus. This keyboard controller uses programmed I/O rather than direct memory access. The operating system would most likely determine what key was pressed occurs by
Question 2: Suppose an OS performs the following operations on an SSD:
and makes sure that all the operations result in changes to the flash chips of the SSD rather than just modifying any DRAM cache the SSD controller may have.
Which of the following are true about this process?
Select all that apply
Question 3: In the FAT filesystem with 1KB clusters, truncating a file foo/bar/baz.txt
from 2.5KB to 1.5KB requires modifying
which of the following? Ignore any updates to creation, modification, and access times.
Select all that apply
Question 4: Suppose a inode-based filesystem has 5 direct blocks, 1 indirect block, and 1 double-indirect block in its inode. If the filesystem uses 1KB (1024 byte)blocks with 2 byte block numbers, then how many blocks are allocated solely to store block numbers for a 1MB (1024 * 1024 byte) file?
Question 1: Suppose a system uses RAID 4 across 5 disks holding a total of 12 sectors of data, where the data on the disks is laid out as follows:
Disk 1 | A1 (sector 0) | B1 (sector 4) | C1 (sector 8) |
---|---|---|---|
Disk 2 | A2 (sector 1) | B2 (sector 5) | C2 (sector 9) |
Disk 3 | A3 (sector 2) | B3 (sector 6) | C3 (sector 10) |
Disk 4 | A4 (sector 3) | B4 (sector 7) | C4 (sector 11) |
Disk 5 | Ap = A1 XOR A2 XOR A3 XOR A4 | Bp = B1 XOR B2 XOR B3 XOR B4 | Cp = C1 XOR C2 XOR C3 XOR C4 |
Suppose all Disk 3 is inaccessible to a hardware failure. How many sectors must be read in order to read sectors 3, 4, 5, and 6 into memory, recovering using the parity Disk 5 if necessary?
Question 2: Compared to a inode-based filesystem that does not use block groups, a filesystem that uses block groups lowers distance on disk between _____.
Select all that apply
Question 3: Suppose a filesystem uses redo logging and supports renaming a file. As part of a renaming the file, the filesystem simulatenously updates the modification time of the directory. Using redo logging, The filesystem attempts to ensure that the renaming operation either updates both the file name and the directory's modification time or updates neither. What would be most useful for the filesystem to store in its log for this operation?
Question 4: In a copy-on-write filesystem that supports snapshots, removing a file X in a directory A will
most likely create new copies of ______. Ignore any changes required to update modification
times, access times, etc.
Select all that apply
Question 1: To make a server that handles multiple clients at the same time in the POSIX
socket API, which of the following strategies would work?
Select all that apply
Question 2: In POSIX internet sockets, a successful to bind()
typically
Select all that apply
Question 3: Which of the following are consistent with a stateless protocols a network file server?
Select all that apply
Question 4: Using remote procedure calls is typically unlike normal (local) procedure calls because _____.
Select all that apply
Question 1: Suppose two systems use NFSv3, with stateless servers and its close-to-open consistency model, and programs on the two machine access the shared file as follows, where (1) and (2) represent unknown values:
System A | System B |
---|---|
open file | |
write A to byte 0-1023 of file | |
write B to byte 1024-2047 of file | |
close file | |
open file | |
write X to byte 0-1023 of file | |
open file | |
write Y to byte 1024-2047 | |
close file | |
read (1) from byte 0-1023 | |
close file | |
open file | |
read (2) from byte 0-1023 | |
close file |
If system A and B both do caching of files on the shared filesystem
if they have available memory as allowed by the
NFS protocol and its consistency model,
which are possible values of (1) and (2)? (Consider both cases where A and B
have available memory for their caches and where they do not.)
Select all that apply
Question 2: Consider a system performing two-phase commit with two workers A and B
and one coordinator. Suppose the coordinator sends a message to both
workers to prepare to do an operation. Then, both worker A and worker B
send their 'agree/vote to commit' message to the coordinator, but worker A's
message is lost due to a temporary network failure. Then, worker A loses
power. How can the system recover from this failure?
Select all that apply
Question 3: If we want to allow programs controlled by certain users to play audio on a POSIX-like machine but not
allow others to play audio, which of the following would be suitable approaches?
Select all that apply
Question 4: Comparing a capability-based system with an access-control-list-based system, which of the
following operations are substantially more difficult in the capability-based system?
Select all that apply
Question 1 (0 points): Suppose a guest operating system is running in a virtual machine implemented using trap-and-emulate. A user program running in the guest operating system tries to access memory that is not allocated but will be allocated on demand by the guest operating system. What will happen?
Suppose a hypervisor uses shadow page tables to implement virtual memory and fills in these shadow page tables on demand as required by page faults that occur while the guest operating system is running, but does not mark the guest page tables as read-only or invalid. (We called this the "virtual TLB" strategy in lecture.)
On a system with 4KB pages the hypervisor allocates the guest operating
system machine memory addresses 0x1000000 through 0x2000000, so that
physical address 0x0 in the guest OS corresponds to machine address 0x1000000
in the guest OS, and 0x1 to 0x1000001 and so on.
Question 2 (0 points): (see above) If a last-level guest page table entry contains page number 0x40, then the corresponding shadow page table entry should contain what page number?
Question 3: (see above) Shadow page table lookups are performed using _____________.
Question 4: Many operating systems avoid microkernel-based designs for performance reasons.
Which of the following are performance issues that microkernel-based designs like
seL4 are likely to experience compared to a monolithic kernel design like Linux?
Select all that apply