1/29
Looks like no tags are added yet.
What is the operating system (OS)?
The operating system is a special program that sits between users/applications and raw hardware. It turns hardware into something applications can use and makes sure the whole system runs correctly and efficiently
What are the two roles the operating system takes on to do its job?
Translator – The OS simplifies complicated hardware through abstraction. The programs never touch the CPU directly – they run as processes. They don’t deal with raw memory chips – they get their own neat address space. They don’t deal with storage – they see files and folders
Referee – The OS divides up resources and allocates them efficiently & fairly among programs. It also protects programs from each other so one crashing app can’t wreck another.
What are the three problems that every modern OS faces?
Virtualization – the art of illusion and making each program believe it has the whole machine to itself
Concurrency – the problem of many things happening at once and giving overlapping programs tools (i.e locks & semaphores) to hide their chaos from eachother
Persistence – the problem of remembering data despite reboots, crashes, and power cuts
In the earliest days, a computer ran one program at a time. This is called:
Uniprogamming
Now, every OS can run many programs at once. This is called:
Multiprogramming
What is the idea that OS designers use to manage the downsides of multiprogramming (which includes difficulty managing the OS machine’s resources)?
The Process
What is a process? (In relation to a program)
A program is lifeless code and data sitting on a disk.
A process is that program running: It is a live copy of the progam’s code and data in memory.
What is the formal definition of a process
An execution stream together with its execution state
Why do processes matter?
They allow the OS to pause a running program in the middle and resume it later. This gives the OS the flexibility to share the machine well.
What are the three basic actions on processes
Create
Destroy
Wait (wait for another process to finish)
What are the 4 steps the OS takes to create a process?
It copies the program’s code and static data from disk into memory
It sets aside space for a stack
It sets aside space for a heap
It sets up I/O.
- In Unix/Linux, every process starts with three open files: stdin, stdout, and stderr

What are the three states of life for a process?
Running – it’s executing instructions on the CPU
Ready – it has everything it needs and is waiting for the CPU
Blocked – it’s waiting for some event (i.e disk transfer finishing or a lock becoming free)
What are the two ways resources can be shared during virtualization?
Time-sharing – processes take turns and only one uses the resource at a time (this is how the CPU is shared)
Space-sharing – each process gets a slice of the resource (this is how memory and disk are shared)
What is direct execution and its 3 problems?
Direct execution: let the process run straight on the hardware. The OS sets it up, jumps to main(), and steps aside.
Problem 1: Process could do something forbidden
Problem 2: Process could run forever and the OS would never get the CPU back
Problem 3: Process could do something slow and waste the CPU while it waits
Solution of direct execution
Limited direct execution – Processes run directly on the hardware, but the OS and hardware keep control at key moments
How does Limited Direct Execution fix Problem 1 of Direct Execution (Process could do something forbidden)
The hardware has a mode bit with 2 modes:
User Mode (where user processes run)
Kernel Mode (where the OS runs)
Some instructions are only allowed in kernel mode. if a user process tries one, the process is terminated.
What happens when a process legitimately needs to be in kernel mode?
The process makes a system call (a request for the OS to do the work)
The system call uses a trap to switch into kernel mode
How does kernel return to user mode?
The kernel sets the mode bit back and loads the process’s next instruction address into the PC. It does both in a single instruction.
How does Limited Direct Execution fix Problem 2 of Direct Execution (a process could run forever)
The hardware has a timer interrupt that fires on a regular schedule, and user processes can’t disable it.
Each interrupt hands the CPU back to the OS.
The OS’s dispatcher can then stop the running process, save its registers in its PCB, and context-switch to another process.
This is called forced multitasking.
How does Limited Direct Execution fix Problem 3 of Direct Execution (a process could waste the CPU on slow operations)
When a process starts a slow operation, the OS marks it blocked and puts it in the queue for that event.
The CPU goes to a ready process from the ready queue.
When the event finishes, the blocked process moves back to ready and waits its turn.
What is a Scheduler?
The OS policy that looks at the ready queue and decides which process gets the CPU next, and for how long.
Then, the dispatcher actually performs the switch.
Turnaround time vs. response time
Turnaround time is how long until a job finishes (completion – arrival)
Response time is how long until a job first runs (first run – arrival)
Preemptive vs non-preemptive
A non-preemptive scheduler lets a job keep the CPU until it gives it up (by doing I/O or calling exit).
A preemptive scheduler can take the CPU away from a running job at any time.
FIFO / FCFS (First In, First Out / First Come, First Served)
Runs jobs in the order they arrive. It's simple and works well when jobs are the same length. Its weakness is the convoy effect (short jobs get stuck behind long ones)
SJF (Shortest Jobs First)
Always runs the job with the shortest run time. Fixes FIFO’s convoy effect. Its weakness is that it’s non-preemptive, so short jobs that arrive while a long job is running still have to wait.
STCF (Shortest Time-to-Completion First)
A preemptive version of SJF that always runs the job closest to finishing. This fixes SJF’s late-arrival problem by pausing a long job when a shorter one arrives.
Its weakness is that it needs to know run times in advance.
RR (Round Robin)
Gives each ready job a fixed time slice (time quantum) in turn. This fixes the poor response time of FIFO, SJF and STCF, and it doesn't need to know run times.
Its weakness is worse turnaround time (jobs take longer to finish)
MLFQ (Multi-Level Feedback Queue)
Learns from each job’s past behavior, so it works without knowing run times. It’s closest to what real systems use.
MLFQ Rules
Higher-priority queues run first.
Jobs at the same level share the CPU in round robin.
New jobs start at the top.
A job that uses its whole time slice is demoted one level.
MLFQ’s Two Problems & The Priority Boost
Starvation: low-priority jobs may never run if higher queues stay busy.
Inflexibility: a job that starts as batch but becomes interactive stays stuck at a low priority.
Priority Boost: periodically boost all jobs back to the top priority