Start from foundations · Course contents · فارسی
Next lesson: CPU scheduling from scratch: FCFS, SJF and timelines
A browser is open, music is playing and a file is being saved. Each needs processor time, memory and devices. If programs used these facilities without coordination, who would manage execution turns, file access and memory boundaries?
An operating system provides an execution environment and services while managing resources. This first lesson in OS-01 — Foundations and processes separates programs from processes and “running” from “existing.” No architecture or programming background is assumed. This is not the entire OS-01 chapter or the whole subject.
1. Three components with different roles
| Component | Role in this model |
|---|---|
| CPU — processor | Executes program instructions. |
| RAM — main memory | Holds instructions and data needed for current work. |
| SSD or persistent storage | Stores files and programs persistently. |
A program file may be on the SSD; when execution starts, the system makes required instructions and data available. Loading and virtual-memory details come later. We need not assume the complete program file is always copied into RAM all at once.
The CPU is not permanent file storage. RAM does not execute a program instead of the CPU; it supplies instructions and data for execution. This simplified distinction is enough to begin.
2. What does the operating system do?
It supplies policies and mechanisms for CPU time, memory, files and devices. The processor executes program instructions; the operating system does not perform every application's calculation on its behalf.
The central privileged component is the kernel. An ordinary program uses operating-system interfaces for services such as opening a file. A system call requests kernel services. Libraries often offer a convenient interface, but not every library function is a system call.
Reading a file involves management such as permissions and data location. File systems and caches come later; retain the relationship “a program requests a managed service from the kernel.”
3. Programs differ from processes
A program is stored instructions, such as an editor's executable file. A process is an instance whose execution has begun, together with associated state and resources.
Two independent executions of the same editor can create two processes. Their code may be shared, while current execution positions and data differ. An application can also create several processes, so windows or application names do not uniquely determine process counts.
A file merely existing on storage does not establish a process executing it. Conversely, a process without the CPU right now may still be alive: it may await its turn or some data.
4. What execution state must be remembered?
Continuing requires knowing the next instruction and progress already made. A processor has very fast storage locations called registers for current values. The Program Counter, PC, identifies where instruction execution continues; it does not count processes.
The operating system keeps process-management information in a structure commonly called the Process Control Block, PCB, such as identity, state and execution/resource-management information. Exact fields depend on design; no long memorized list is needed now.
When the running process changes, necessary old state is saved and new state restored. This is a context switch, not copying the complete executable to disk on every turn. Real switches have costs.
5. Three principal states in the introductory model
- Running: currently executing on the CPU in our model.
- Ready: able to execute, awaiting CPU selection.
- Blocked / Waiting: requires an event such as I/O completion; a free CPU alone does not remove that obstacle.
We assume one core with one active execution stream, deferring threads and hardware multithreading. Two processes are not simultaneously Running on this one modeled core, but several can exist and progress by turns.
If a process loses its CPU turn without an event obstacle, it returns from Running to Ready. This preemption differs from becoming Blocked for I/O.
Event completion makes a process ready, not necessarily immediately running. Selection depends on scheduling policy and other work. This distinction prevents confusing every kind of waiting with waiting for the CPU.
6. A complete timeline
Processes A and B are ready. Educational assumptions: one core, zero switching cost, A selected first. A needs one CPU unit, then waits two units for I/O, then needs one more CPU unit. B needs two CPU units with no I/O. I/O — input/output means device work such as obtaining data; its waiting period can overlap another process's CPU execution.
| Interval | CPU activity | A | B |
|---|---|---|---|
| 0–1 | A executes | Running | Ready |
| 1–3 | B executes | Blocked for I/O | Running |
| 3–4 | A resumes | Running after event completion and selection | Finished |
At time one A has not finished; it is waiting. At time three its I/O completes and it becomes ready. This example selects it immediately because B also finishes then. Immediate selection follows the example's data, not a universal rule that I/O completion directly means running.
Not every process must visit Blocked: one with no event wait may go from running to termination. A state diagram shows permitted transitions, not a compulsory path for every program.
7. Concurrency differs from parallel execution
Concurrency means multiple tasks make progress over an overlapping period, possibly by alternating CPU execution. Parallel execution means multiple tasks actually execute at the same instant on suitable execution units.
In our single-core model A and B take CPU turns. Work still overlaps in time: A's I/O device activity overlaps B's CPU execution. Multiple cores may also execute multiple processes' CPU instructions at once. Several open applications alone establish neither core count nor parallel CPU execution.
8. Test-taking notes
- Ready differs from Blocked: one awaits CPU selection, the other an event.
- I/O completion means becoming ready: CPU selection is a separate transition even if immediately adjacent in one example.
- Switching is not free: assume zero cost only when stated.
- Alive does not mean Running: lacking CPU time or awaiting a file does not imply termination.
- Read the model: core count, arrivals, I/O and selection policy can change scheduling answers.
All questions are original educational practice, not claimed official exam questions or verified exam allocation.
9. Independent practice: open answers after attempting
- A program file exists on SSD, but execution has not begun. Is that sufficient for a process executing it?
Answer and reasoning 1
No. A program is stored instructions; a process is a begun execution instance with associated state. File existence alone does not mean execution began.
- A process awaits a file read and the CPU becomes free. Does free CPU alone make it able to continue?
Answer and reasoning 2
No: its obstacle is event completion. After completion it becomes Ready and can be selected. Ready and Blocked are different reasons for not executing.
- Original practice question: In this three-state model, I/O completion causes which transition? A) Blocked to Ready. B) Ready to terminated. C) Terminated to Running. D) Always directly Blocked to Running.
Answer and reasoning 3
A. CPU selection is separate. A process may be selected immediately after becoming ready, but the two transitions and their causes remain distinct.
- Why do two independent editor executions not have identical execution state merely because the program is the same?
Answer and reasoning 4
They may hold different files, occupy different instruction positions or await different events. Program identifies instructions; each process instance has its own associated state and resources.
- In section 6's timeline, is A terminated during interval 1–3? Is the CPU idle?
Answer and reasoning 5
Neither. A is alive but waiting for I/O, while B executes on the CPU. At three A becomes ready and, after selection, runs its final unit.
- Why does “four open programs imply four cores” fail?
Answer and reasoning 6
One core can alternate tasks to provide concurrency. Window, process and core counts need not agree. Parallel CPU execution requires hardware and execution-model information.
10. Continue and review
Without looking, distinguish a program from a process using an example. Give different nonexecution reasons for Ready and Blocked, then explain what must happen after event completion.
Continue when: exercises 1, 2, 3 and 5 have reasons, not just memorized state names. For mixed-up states ask, “Could this process continue if it had CPU now?” If not, identify its event obstacle. For program/process confusion, separately label the executable file and two independent executions.
Later invent one case with one Running and one Ready process, then another with the second Blocked. Neither page availability nor visits record study or mastery. The remainder of OS-01 covers system calls, threads and execution-state details; the whole chapter is not complete. Operating systems contents · Start from foundations.
References and authorship
Text, timeline, questions and diagram are original teaching material. Suggested further reading: Remzi and Andrea Arpaci-Dusseau, Operating Systems: Three Easy Pieces, introductions and processes; Silberschatz and colleagues, Operating System Concepts, introductory/process material. Recommendations do not claim online review of a specific edition, official questions or verified 1406 coefficients. Diagram provenance.
Next lesson: CPU scheduling from scratch: FCFS, SJF and timelines