1/44
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
What is a program?
A program is a set of instructions stored on a disk designed to perform a task.
What is a process?
A process is an active instance of a program with its own execution context and owned resources, running on the CPU while being stored in the RAM with a PC specifying the next instruction.
T/F Only one process can run the same program.
F. Multiple processes can run on the same program.
What is the main difference between a process and a thread?
A process has its own resources like address space not shared between processes, while a thread is a unit of execution inside a process that shares its resources.
How is the process address space divided and what does each section handle?
(1) Text (executable code/instructions)
(2) Stack (temporary data storage)
(3) Heap (dynamically allocated memory during runtime)
(4) Data (global variables)
What are the typical states of a process?
(1) New
(2) Ready
(3) Running
(4) Waiting (Blocked)
(5) Terminated
What is an OS?
An OS is a software between user/applications and hardware that provides abstraction, resource management, protection and efficiency.
What are the key motivations of the OS? (5)
(1) Support for concurrency
(2) Virtualization
(3) Portability
(4) Deal with diversity
(5) Transparency
What are the core purposes of an OS? (3)
(1) Abstraction (hide OS complexity)
(2) Resource management (share CPU, memory, I/O. -> share hardware efficiently)
(3) Protection (prevent apps from harming OS/other apps)
What are the responsibilities of an OS?
(1) Memory Management
(2) I/O Management
(3) Process Management
(4) File Management
When forking, who gets the PID and who gets 0?
The parent process from who we originally forked from gets the PID and the child process gets 0.
Why is it useful for the parent and child to have different values?
To allow the child and the parent process to differentiate each other by testing the value of x. (let the parent know it is the parent process and the child that it is the child)
What are the two ways a process can be terminated?
(1) The process calls exit(status) on itself.
(2) The parent terminates it. (abort/kill)
What are the special cases of termination and how do they happen?
(1) Orphan: The parent is terminated before the child.
(2) Zombie: The child is terminated, parent did not call wait().
What is a system call?
A system call is a controlled request for OS services, invoked via a trap.
What are the steps of a system call?
(1) Put syscall number in register
(2) Execute trap
(3) Switch to kernel mode
(4) OS executes code
(5) Return to user mode
What is a mode switch?
A mode switch allows for switching between user and kernel mode.
What is a context switch?
A context switch allows for saving a process state and restoring another.
What is the key difference of the switches?
A mode switch is focused on privilege levels
who is allowed to use what. A context switch is focused on which process runs.
What does the OS do during a context switch?
Saves the context of execution of one process in its PCB and loads the context of execution of another process.
What is a DMA?
A hardware component that transfers large blocks of data directly between device and memory without using the CPU.
What happens without a DMA?
CPU waits for I/O, performs many copies, handles many interrupts. This makes it inefficient.
What happens with a DMA? (Advantages)
Fewer CPU operations, fewer interrupts, CPU executes other work in parallel.
What is an I/O device?
Devices that humans/systems use to communicate with the computer.
What is an interrupt?
A hardware generated signal for controlled entry into OS causing the CPU to run OS interrupt handlers.
What is a trap?
A software generated interrupt, used for system calls or raised on errors.
What is a buffer?
A buffer is a designated, temporary storage in physical memory for data that is being moved between processes/locations.
What are buffers used for?
(1) Handle speed mismatch -> Process must wait for the relatively slow I/O to complete before it can send new data (or vice versa)
(2) Handle granularity mismatch -> Application may expect to receive data in smaller or larger pieces than the data sent by the I/O (and vice versa)
(3) Allow process switching during I/O
In what aspects do the CPU scheduling frameworks differ from each other?
(1) When to schedule: determines at which events the scheduler is activated.
(2) Who to schedule: determines which process is chosen next based on a priority function among ready processes (e.g. shortest job, earliest arrival).
(3) What arbitration rule: determines how to choose between processes with equal priority (e.g. FCFS)
What are the three main CPU scheduling algorithms?
(1) FCFS (First-Come First-Serve)
(2) SJF (Shortest Job First)
(3) RR (round Robin)
When is something considered atomic?
When an instruction contains only ONE reference to a shared variable.
If x and y are shared variables and z is private, is the statement x := y * z atomic? Why or why not?
No. It contains two references to shared variables (reading y and writing to x). To be atomic, it can have only one shared reference.
Why is y++ generally not considered atomic?
At machine level, we need to do 3 things for this instruction. We read y, increment y, and write y. This involves two references to a shared variable (one read, one write).
What is a race condition?
A situation where the correctness of a concurrent program depends on the specific interleaving or order in which instructions are chosen for execution.
What is an example of a race condition?
In a program that assumes a state is not changed between a test (like if (x > 0)) and an action (like x--), another thread could change x in between, leading to an error.
What is interference?
When the truth of an assumption which would be true in local reasoning, is made false by the actions of a different concurrent task.
What are the four correctness concerns in concurrent programs or systems?
(1) Functional Correctness (Mutual Exclusion)
(2) Minimal waiting
(3) Absence of deadlocks
(4) Fairness
If two POSIX processes P1 and P2 both execute x := x + 1 (starting at x = 0), why is the final value of x always 1 in both processes?
The final value is 1 in both. Because they are processes, they have separate, non-shared memory spaces
each increments its own private copy of x.
If two Threads T1 and T2 execute x := x + 1 and x := x + 2 concurrently (starting at x = 0), list all the possible final values of x.
Possible values are 1, 2, or 3.
3: Sequential execution.
1 or 2: Interleaved execution where one thread overwrites the other's update.
Why is communication and context switching generally faster between threads than between processes?
Threads share the same address space. Creation and context switching are faster because the OS does not need to copy memory spaces or switch page tables.
What is busy waiting?
A task or process repeatedly checks a condition in a loop without going to sleep or yielding the CPU. Instead of being suspended by the OS, it keeps running and executing instructions until required conditions are true.
When is busy waiting acceptable?
(1) When the waiting time is guaranteed to be short.
(2) When it is the only task the processor can perform.
Why is busy waiting generally discouraged?
It wastes CPU cycles that could be used by other productive processes, leading to decreased system efficiency and potentially causing priority inversion.