CPU Virtualizing: Processes & Scheduling Flashcards
What happens when you run a program?
Loads from disk to memory
The CPU, using its instruction Set Architecture (ISA), sequentially:
Fetches an instruction from memory.
Decodes to identify the specific command.
Executes the identified operation(e.g, adding numbers, memory access, function jumps.)
Move to next instruction
The cycle repeats billions of times every second until the program finishes
Despite this simple model, many other complex processes occur during a program’s execution.
Explain short: What is the goal of process abstraction?
The goal of process abstraction is to run multiple processes concurrently, by time sharing the cpu. We then need mechanisms (context switch) and policy(scheduler). This makes the illuision that each program has it’s own isolated machine.
What is virtualization of the CPU?
It involves a single cpu acting as if it were multiple seperate CPUs- Enables users to run many concurrent programs
Which states can a process be? Explain them.
Running: The process is actively executing instruction on a processor.
Ready: The process is prepared to run but isn’t currently chosen by the OS to execute.
Blocked: The process is waiting for an event before it can proceed. For instance, a process become blocked when initiating an I/O request to a disk or network, allowing another process to use the processor in the meantime
Running to Ready: The OS interrupts the running process and puts it back in the queue to wait its turn. Running to Blocked: The process initiates I/O, like reading from a disk, and can't run until the I/O is done. Ready to Running: The OS decides it's this process's turn to run. Blocked to Ready: The I/O operation that was blocking the process is now finished.
What does fork() do? What does exec() do What does wait() do?
The fork() function creates a new process, which is an exact copy of the calling process. It’s like having two identical versions of the original process, both seemingly continuing from where fork() was called
The wait() system call allows the parent process to pause and wait until its child process finishes. Once the child completes, the parents resume, and wait() provides the child’s PID as its return value. This will always make the child go first.
Exec()
Loads the code and static data from the file.
Overwrites current code segment and static data of the process.
Re-initializes the heap and stack to match the new program’s requirements.
What different modes can an OS run an executable from?
User and kernel mode
What is kernel mode?
In Kernel mode:
The OS can run system calls. The OS doesn't trust the user's stack or provided addresses. The OS has full access to the hardware, like using any CPU instruction and accessing any memory. Kernel mode is for the most trusted and low-level OS functions. Crashes in kernel mode can stop the whole computer.
What are the two types of scheduler?
Preemptive and non preemptive
What is a context switch?
For example when a process switches from user to kernel mode. It then saves context (PC, registers, kernel stack, pointer) of process on kernel stack
What is SJF (shortest-job-first)?
It runs the shortest job available, not preemptive
What is FIFO (first-in first-out)?
It runs the process with the shortest arrival time
What is RR (round-robin), and how does it work?
A scheduling algorithm.| It runs each process on a given time quatum. This could be 2ms.
Why do we want to have a scheduler?
Maximize CPU usage.
Minimize turnaround time (arrival to completion).
Minimize response time (arrival to first scheduling).
Ensure fairness for all processes.
Minimize overhead by running processes long enough to cover context switch costs (e.g., 1 microsecond).
What is stride scheduling?
Each process is assigned a ticket value.
We calculate a “stride” for each process using a fixed number (e.g., 1000 or 10000).
A “pass” value is increased by the stride value for each process.
The operating system selects the process with the lowest pass value to run.
If multiple processes have the same pass value, the one with the lowest stride value runs first.
If both pass and stride values are identical, the process that entered the scheduling queue first gets to run first.
What is the formula for turnaround time? What is turnaround time?
Tturnaround = Tcompletion - Tarrival
Scheduler performance is measured using turnaround time, which is the duration from a process entering the queue to its completion. Interestingly, better turnaround times can sometimes mean less fairness in scheduling.