Introduction to Operating Systems
What an operating system is, how the hardware underneath it is organised, why the OS runs in two modes, and the five classic types of OS with their trade-offs.
What you will be able to do
- Name the four components of a computer system and place any piece of software in the right one.
- Explain how CPUs, device controllers and memory share a common bus and why interrupts exist.
- Contrast asymmetric and symmetric multiprocessing and list the three advantages of multiprocessors.
- Describe the four core functions of an OS plus the five supporting activities.
- Explain dual-mode operation, the mode bit values, and why a user-mode crash cannot take the OS down.
- Compare batch, multiprogramming, multiprocessor, distributed and real-time systems with advantages and disadvantages.
What an operating system actually is
The OS is the one program that is always running, and everything else asks it for permission.
An operating system is a collection of software that manages the computer's hardware and software resources and provides common services for programs. That definition has two halves and both matter. It manages resources: only one program can own the CPU at a given instant, and someone has to decide who. It provides services: your program does not know how to talk to a hard disk, so it asks the OS to read a file for it.
Think of a computer system as four layers stacked on top of each other. The slides call these the four components of a computer system, and the very first recap question asks you to spot the odd one out.
The four components, from bottom to top
| Component | What it is | Examples |
|---|---|---|
| Hardware | Provides the basic computing resources | CPU, memory, I/O devices |
| Operating system | Controls and coordinates use of the hardware among applications and users | Linux, Windows, macOS, Android |
| Application programs | Define the ways the resources are used to solve users' problems | Word processors, compilers, web browsers, database systems, video games |
| Users | Whoever is using the system | People, machines, other computers |
How the machine is wired: organisation and operation
Everything hangs off one shared bus and competes for memory cycles.
Before you can understand what the OS does, you need a picture of the machine it runs on. A modern computer has one or more CPUs and a set of device controllers (disk controller, USB controller, graphics adapter) all connected through a common bus that gives them access to shared memory. The CPUs and the devices execute concurrently, and because they all want memory, they compete for memory cycles.
Computer-system operation, point by point
- I/O devices and the CPU can execute concurrently. While the disk is spinning to find a sector, the CPU is running other instructions. This is the single fact that makes everything else in the course necessary.
- Each device controller is in charge of a particular device type. The disk controller knows disks, the USB controller knows USB. The CPU never talks to the raw device.
- Each device controller has a local buffer. Data coming from a device lands here first.
- I/O is from the device to the local buffer of the controller. Then the CPU moves data between main memory and those local buffers.
- The controller informs the CPU that it has finished by causing an interrupt. The CPU does not poll the device forever; it gets tapped on the shoulder.
Computer-system architecture: one processor or many
Multiprocessors buy throughput, economy and reliability, but they come in two very different flavours.
Most systems use a single general-purpose processor, and many also carry special-purpose processors (a disk controller often has its own tiny CPU, a GPU is another). But the trend that matters is the rise of multiprocessor systems, also called parallel systems or tightly-coupled systems: two or more processors sharing memory and the bus.
Three advantages of multiprocessors (memorise the order)
- 1Increased throughput. More processors, more work per second. Not N times more, because they fight over shared memory and need coordination.
- 2Economy of scale. Sharing one memory, one power supply and one set of peripherals is cheaper than buying N separate machines.
- 3Increased reliability. If one processor dies, the others carry on more slowly. The slides call this graceful degradation; a system engineered to survive any single failure is called fault tolerant.
The two types of multiprocessing
Asymmetric multiprocessing (AMP)
- Each processor is assigned a specific task.
- Usually a boss-worker arrangement: one processor schedules, the others do the work it hands out.
- Slide example: ARM Cortex-A73 (big) + Cortex-A53 (LITTLE). The big cores run heavy work, the little cores run background tasks to save power.
Symmetric multiprocessing (SMP)
- Each processor performs all tasks. No boss. Any core can run the OS, any core can run a user program.
- All processors share memory and are peers.
- Slide examples: Intel Core, AMD Ryzen. Your laptop is almost certainly SMP.
Two more terms from the slides. A dual-core design puts two cores on one chip, so a system can be multi-chip and multicore at the same time. At the very top end, a chassis containing multiple separate systems (a blade server) is also counted as one multiprocessor system.
What the OS does all day: functions and activities
Four core managers plus five housekeeping jobs.
The slides split the OS's work into four functions (the big managers) and five other important activities (the housekeeping). Examiners love asking you to classify a task into one of these buckets, so learn the exact names.
The four functions of an OS
| Function | What it means | Where you see it |
|---|---|---|
| Processor management | In a multiprogramming environment the OS decides which process gets the processor, when, and for how long. This function is called process scheduling. | Linux top showing processes taking turns on the CPU |
| Memory management | Management of primary (main) memory: a large array of words or bytes, each with its own address. The OS decides who gets which addresses. | A browser tab using 400 MB while the OS keeps it from reading another tab's memory |
| Device management | The OS manages device communication via their respective drivers. | Plugging in a USB drive and having it appear without your program knowing the hardware |
| File management | A file system is organised into directories for easy navigation. Directories contain files and other directories. | ls on Linux or File Explorer on Windows |
The five other important activities
- Security. Passwords and similar techniques prevent unauthorised access to programs and data.
- Control over system performance. Recording delays between a request for a service and the response from the system.
- Job accounting. Keeping track of time and resources used by various jobs and users. This is how a cloud provider knows what to bill you.
- Error detecting aids. Production of dumps, traces, error messages and other debugging aids. A Linux core dump or the Windows blue screen minidump is this activity.
- Coordination between other software and users. Assigning compilers, interpreters, assemblers and other software to the users of the system.
OS operations: interrupts and dual mode
The OS is asleep until an interrupt wakes it, and it protects itself with a single bit.
A modern OS is interrupt driven. It does not sit in a loop checking things. It waits, and when something happens it gets woken by an interrupt, handles it, and goes back to sleep or hands the CPU to a user program. Interrupts come in two families.
Two families of interrupts
Hardware interrupt
- Raised by one of the devices.
- Keyboard press, mouse movement, timer tick, disk I/O completion.
- Arrives at unpredictable times.
Software interrupt (exception or trap)
- Software error, for example division by zero.
- A request for operating system service (a system call).
- Other process problems: an infinite loop, or processes modifying each other or the OS.
Now the protection question. If any program could execute any instruction, one buggy program could overwrite the OS or turn off interrupts forever. So the CPU supports dual-mode operation. A mode bit in the hardware says whether the CPU is currently running user code or OS code, and certain privileged instructions simply refuse to execute unless the bit says kernel.
One trip through the mode bit (follow the slide diagram)
- 1
User process executing
Mode bit =
1. The program is running its own instructions in user mode. - 2
Gets a system call
The program needs the OS (say, to read a file). Hardware sets mode bit = 0 before switching to kernel mode.
- 3
Execute system call
The OS runs the privileged work with mode bit =
0. - 4
Return from system call
Hardware sets mode bit = 1 before switching back to user mode, and the program carries on.
User mode vs kernel mode (this exact table is on the slides)
| Aspect | User mode | Kernel mode |
|---|---|---|
| Privilege level | Lower-privileged | Higher-privileged |
| Access to hardware | Restricted | Unrestricted |
| Access to system memory | Limited | Full access |
| Execution environment | User-level applications | Operating system and kernel components |
| Error isolation | Processes in user mode are isolated | Kernel manages process isolation |
| Purpose | Run user applications | Manage system resources and hardware |
| Exception handling | Limited exception handling capabilities | Comprehensive exception handling |
| Stability | Application crashes do not crash the OS | Kernel issues can crash the entire OS |
Types of OS, part 1: batch and multiprogramming
From punch cards handed to an operator to several jobs living in memory at once.
The slides list five types of operating system: simple batch, multiprogramming, multiprocessor, distributed, and real-time. For each one you need the idea, the advantages, the disadvantages and an example. We take the first two here.
How a simple batch system worked
- 1
User prepares the job
The user punches the program and data onto punch cards.
- 2
Submit to the operator
The user hands the deck to the computer operator. There is no interaction after this point.
- 3
Operator sorts into batches
The operator collects jobs from many users and groups them into batches with similar needs (all FORTRAN jobs together, for instance).
- 4
Batches go to the processor one by one
All the jobs of one batch are executed together. The user comes back later for the printout.
Simple batch OS
Advantages
- The processor knows how long a job will take while it is in the queue.
- Multiple users can share the batch system.
- Idle time is very low: the next job is always ready.
- Easy to manage large, repetitive work.
Disadvantages
- Operators must be well trained in batch systems.
- Batch systems are hard to debug (you find out hours later).
- It is sometimes costly.
- If any job fails, the other jobs wait for an unknown time.
Examples on the slides: payroll systems and bank statements. Both are still batch today: your bank computes interest for every account overnight in one run, with nobody sitting at a keyboard. The trade-off is high throughput but low responsiveness: the machine is always busy, but no individual user gets an answer quickly.
Multiprogramming is the next step. Sharing the processor when two or more programs reside in memory at the same time is multiprogramming. The OS keeps several jobs in memory at once; this set is a subset of the job pool on disk. It picks one job and starts executing it. When that job has to wait (say for I/O), the OS switches to another job in memory. The goal: the CPU is never idle unless there are no jobs to process.
Multiprogramming OS
Advantages
- High and efficient CPU utilisation.
- The user feels that many programs are allotted the CPU almost simultaneously.
Disadvantages
- CPU scheduling is required. Someone has to choose which job runs next.
- Memory management is required to fit many jobs in memory at once.
Types of OS, part 2: multiprocessor and distributed
Shared memory under one OS, or independent machines talking over a network.
A multiprocessor operating system runs on a system with several processors that share a common physical memory. It provides higher computing power and speed. Two things to remember about how it is organised: all processors operate under a single operating system, and the multiplicity of processors is transparent: a program does not know or care which processor it is on.
Multiprocessor OS
Advantages
- Increased throughput: more programs processed per second.
- Cost effective: processors share the resources a single-processor system already has (memory, disks, power).
- Increased reliability: the workload is distributed, so one failure does not stop everything.
Disadvantages
- Failure of even one processor slows the whole system.
- These systems are expensive.
- A more sophisticated OS is required to manage programs and data (synchronisation, shared memory access).
- Large main memory is required.
A distributed operating system is different in kind. It is a collection of autonomous but interconnected computers that communicate over a shared communication network. Each node is independent with its own memory and CPU. There is no shared physical memory; cooperation happens by sending messages. Google's search index spread across thousands of servers is the everyday example.
Distributed OS
Advantages
- All systems are independent, so failure of one does not affect the network communication of the others.
- Resources are shared, so computation is fast and durable.
- Easily scalable: add more machines to the network.
- Data exchange within the network is fast and reliable.
Disadvantages
- Everything relies on a single network; if it fails, all communication stops.
- Languages for building distributed systems are not well defined yet.
- Expensive and not readily available; the software is highly complex and not well understood.
Multiprocessor vs distributed: the one distinction examiners test
| Multiprocessor | Distributed | |
|---|---|---|
| Memory | Shared physical memory | Each node has its own memory |
| Coupling | Tightly coupled | Loosely coupled |
| Communication | Through shared memory | Through messages over a network |
| OS | One OS for all processors | Autonomous machines cooperating |
| Hard problem | Synchronisation and shared-memory access | Fault tolerance and consistency across nodes; transparency via middleware |
Types of OS, part 3: real-time systems
When a late answer is a wrong answer.
A real-time operating system (RTOS) is used when there are very strict time requirements: missile systems, air traffic control, robots. The time between an input arriving and the system responding is the response time, and in an RTOS it must be very small and, more importantly, predictable. A normal OS optimises for average throughput; an RTOS optimises for never missing a deadline.
Hard vs soft real-time
Hard real-time
- Time constraints are very strict; even the shortest delay is not acceptable.
- Missing a deadline is a system failure.
- Examples: automatic parachutes, airbags, systems built for saving life.
Soft real-time
- Time constraints are less strict; a late result is degraded, not catastrophic.
- Examples: online gaming, email systems, weather monitoring.
- A video frame arriving late causes a stutter, not a crash.
Real-time OS
Advantages
- Maximum utilisation of devices and system, so more output from all resources.
- Time assigned for shifting tasks is very small.
- Focus on running applications, less importance to those in the queue.
- Used in embedded systems because programs are small.
- These systems are error-free (the slides' wording; in practice this means designed and verified to be).
Disadvantages
- Very few tasks run at the same time; concentration is on a few applications to avoid errors.
- System resources are sometimes not so good and are expensive.
- The algorithms are very complex and difficult for the designer to write.
- Needs specific device drivers and interrupt signals to respond to interrupts as early as possible.
All five types in one glance
| Type | Key idea | Example |
|---|---|---|
| Simple batch | Jobs grouped by the operator, run one batch at a time, no interaction | Payroll, bank statements |
| Multiprogramming | Several jobs in memory; CPU switches when one waits | Any time-sharing mainframe; the basis of every modern OS |
| Multiprocessor | Several CPUs share one memory under one OS | Multi-core servers, your laptop |
| Distributed | Independent machines with own CPU and memory, cooperating over a network | Google's data centres, a cluster |
| Real-time | Strict response-time guarantees | Airbag controller (hard), online game (soft) |
Before the exam
The lines worth memorising, and the mistakes that lose marks.
Remember this
- 1Four components: hardware, OS, application programs, users. A compiler is an application program.
- 2CPUs and I/O devices run concurrently; controllers have local buffers and signal completion with an interrupt.
- 3Multiprocessor advantages: throughput, economy of scale, reliability (graceful degradation).
- 4Asymmetric = each processor has a specific task (ARM big.LITTLE). Symmetric = every processor does everything (Intel Core, AMD Ryzen).
- 5Four functions: processor, memory, device, file management. Processor management = process scheduling.
- 6Other activities: security, performance control, job accounting, error detecting aids, coordination of software and users.
- 7OS is interrupt driven. Hardware interrupt = device. Software interrupt (trap/exception) = division by zero, system call.
- 8Mode bit: user = 1, kernel = 0 on these slides. Privileged instructions run only in kernel mode.
- 9User-mode crash does not crash the OS. Kernel crash can crash the whole OS.
- 10Batch: high throughput, low responsiveness; if one job fails the others wait an unknown time.
- 11Multiprogramming: several jobs in memory (a subset of the job pool); CPU never idle; needs scheduling and memory management.
- 12Multiprocessor OS: shared memory, single OS. Distributed OS: own memory and CPU per node, talks over a network.
- 13Hard real-time: airbag, parachute. Soft real-time: online gaming, email, weather monitoring.
Exam traps
- A compiler is not a component of the computer system, because it is just one more application program sitting on top of the OS.
- Symmetric multiprocessing is not "only one processor active at a time", because SMP means every processor is a peer and all of them run all tasks.
- A user-mode crash is not an OS crash, because dual-mode operation isolates user processes; only a kernel failure can bring down the whole system.
- Kernel mode is not mode bit 1 on this course, because the slides define kernel mode as mode bit 0 and user mode as mode bit 1.
- A distributed system is not a multiprocessor system, because distributed nodes each have their own memory and CPU and communicate over a network instead of sharing memory.
- A software interrupt is not caused by a power outage or hardware failure, because those are hardware events; a software interrupt comes from the running program (division by zero, a system call).
- CPU scheduling is not a benefit of multiprogramming, because the slides list it as a disadvantage: it is a cost you pay to keep several jobs in memory.
- Online gaming is not a hard real-time application, because a late frame degrades the experience without causing failure; hard real-time is airbags and parachutes.
Quiz yourself
One question at a time with instant feedback. Your best score is saved.
Which of the following is not one of the four main components of a computer system?
Not quite
The four components are hardware, operating system, application programs and users. A compiler is an application program, not a component in its own right.
Finished reading?
Mark this lecture as done
Take the quiz above first so your score is saved here.