Basics
Processes
Scheduling
Thread Safety
C & Systems Programming
100

The OS we use in class, and its kernel.

What is Ubuntu and Linux?

100

A running program on an operating system.

What is a process?

100

This style of scheduling allows the OS to forcefully interrupt a process to allow another process to run.

What is preemptive scheduling?

100

See code snippet for Thread Safety 100.

What is the value of x after this pseudocode executes?

idk

100

* is the operator used to dereference a pointer, but this operator is used to find the address of a variable.

What is & (ampersand operator/address-of operator)?

200

The more privileged mode of an operating system, allows execution of all CPU instructions and access to all memory.

What is kernel mode?

200

After a process calls fork and the parent modifies a global variable, does the child see this modification? Why or why not?

No, because they are separate processes with separate address spaces.

200

In Shortest Job First scheduling, long-running processes can suffer from this.

What is starvation?

200

This situation occurs when two or more processes are unable to run because each is waiting for a resource held by another.

What is deadlock?
(patch yesterday...)

200

When compiling a C program using gcc that uses POSIX multithreading functions, this flag must be passed into the gcc command to link the library correctly.

What is -lpthread (or -pthread)?

300

The two main responsibilities of an OS.

What is managing resources and providing hardware abstraction?

300

Name the three state transitions a process undergoes when:

  1. A running process requests to read from disk

  2. Finishes reading from disk

  3. Is chosen by the OS to run again

What is Running to Blocked, Blocked to Ready, and Ready to Running?

300

A process is running on a single-core CPU. It calls sleep(10).

Which statement/statements are necessarily true?

A. The process will return to the CPU exactly 10 seconds after calling sleep(10).

B. The process will be added to the ready queue immediately after calling sleep(10).

C. The CPU will immediately begin executing another ready process.

D. The process will not execute again until at least 10 seconds have elapsed.

Only D is necessarily true.

300

x += 1;

Is this thread safe? Why or why not?

It is not, there can be a context switch between reading the current x and writing to the new x.

300

What is a void pointer?

A pointer that does not have a specific data type associated with it, allowing it to point to any data type.

400

The operating system privilege level sudo operates at.

What is the userspace?

400

Explain how processes and threads differ from each other.

A process is a running program with its own independent resources. A thread is a unit of execution within a process that shares memory and resources with other threads in the same process.

400

This mechanism allows the CPU to temporarily stop its current execution and handle an event such as a timer, keyboard input, or completed I/O. Why can't we simply disable these whenever we enter a critical section?

What is an interrupt?

Allowing a user-level program to disable interrupts would create this security problem: the program could prevent the OS from regaining control of the CPU and potentially take over the system.

400

Although both manage shared resources, a mutex differs from a semaphore because a mutex enforces this rule on lock release.

What is thread ownership (only the thread that locked the mutex can unlock it)?

400

See code snippet for C Programming 400.

How many threads exist at printf?

9 threads.

500

When a process executes this instruction, the CPU saves enough state to resume the process later, switches from user mode to kernel mode, and transfers control to a predefined kernel entry point.

What is a trap instruction?

500

How many processes does the following command create?

{ ls | grep txt > out.txt } &

What is 3?

500

Why might concurrency slow down our programs even if there are no race conditions?

Context switching clears the cache and/or waiting at locks can take time depending on the lock implementation.

500

See code snippet for Thread Safety 500.

How could this lead to deadlock?

Consumer takes the lock first and enters the while loop.

500

See code snippet for C Programming 500.

There are some things wrong with this code. What might they be?

Returning locally allocated memory, buffer overflow with strcpy, pointer arithmetic on a void pointer, and dereferencing a void pointer.

M
e
n
u