Skip to content
Chethan Yadav_
Operating Systems

OS/Lesson 1 of 9/5 min read

Introduction to Operating Systems

What an OS is, its goals, types, kernel architectures, system calls, dual-mode operation and interrupts.


On this page

What is an Operating System

An Operating System (OS) is system software that sits between hardware and applications. It manages hardware resources (CPU, memory, disk, devices) and provides common services to programs.

Two views of an OS:

  • Resource manager: decides who gets the CPU, how memory is split, which process reads the disk next.
  • Extended machine: hides ugly hardware details behind clean abstractions (files instead of disk sectors, processes instead of raw CPU registers).

Goals: convenience (easy to use), efficiency (good hardware utilization), and the ability to evolve.

Core functions

FunctionWhat it does
Process managementCreate, schedule, terminate processes; synchronization and IPC
Memory managementAllocate and free memory, virtual memory, protection
File managementFiles, directories, permissions, storage allocation
Device managementDrivers, buffering, spooling
Security and protectionAccess control, user isolation

Types of Operating Systems

  • Batch OS: jobs with similar needs are grouped and run one after another, no user interaction. Example: early IBM mainframes.
  • Multiprogramming OS: keeps several jobs in memory; when one waits for I/O, the CPU switches to another. Goal: keep the CPU busy.
  • Multitasking / Time-Sharing OS: multiprogramming plus a short time slice per process, so many users feel they own the machine. Goal: low response time. Example: Unix, Linux, Windows.
  • Multiprocessing OS: uses more than one CPU. Symmetric (SMP, every CPU runs the OS) or asymmetric (one master CPU).
  • Distributed OS: many networked machines appear as one system.
  • Real-Time Operating System (RTOS): guarantees responses within strict deadlines. Hard real-time (missing a deadline is a failure, e.g. airbag controller) vs soft real-time (occasional misses allowed, e.g. video streaming).
  • Embedded OS: tiny OS for a dedicated device (routers, washing machines).

Multiprogramming maximizes CPU utilization. Time-sharing maximizes responsiveness. Interviewers like this distinction.

Kernel

The kernel is the core of the OS that is always resident in memory and runs with full hardware privileges. Everything else (shell, utilities, GUI) is user-space software.

Monolithic Kernel

All OS services (scheduler, memory manager, file systems, drivers) run in kernel space as one large program.

  • Fast: services call each other directly.
  • Risky: a buggy driver can crash the whole system.
  • Example: Linux (with loadable modules), traditional Unix.

Microkernel

Only the minimum runs in kernel space: IPC, basic scheduling, low-level memory. Drivers, file systems and networking run as user-space servers.

  • Reliable and secure: a crashed driver can be restarted.
  • Slower: services talk via message passing, needing extra mode switches.
  • Example: Minix, QNX, seL4.

Hybrid kernels (Windows NT, macOS XNU) mix both: microkernel-like structure with performance-critical services kept in kernel space.

Kernel Mode and User Mode

CPUs support at least two privilege levels, set by a mode bit in hardware.

  • User Mode (mode bit = 1): applications run here. Privileged instructions (I/O, changing page tables, disabling interrupts) are forbidden.
  • Kernel Mode (mode bit = 0): the OS runs here with full access.

If a user program tries a privileged instruction, the CPU raises a trap and the OS usually kills the program. This dual-mode operation protects the OS and other programs from faulty or malicious code.

System Call

A system call is the programmatic way a user program asks the kernel for a service. It is the only legal door from user mode into kernel mode.

How it works:

  1. The program calls a library wrapper, e.g. read() in libc.
  2. The wrapper puts the system call number and arguments in registers.
  3. It executes a trap instruction (syscall on x86-64), switching to kernel mode.
  4. The kernel looks up the handler in the system call table, runs it, and returns the result.
  5. The CPU switches back to user mode.
CategoryExamples (Unix)
Process controlfork, exec, exit, wait
File managementopen, read, write, close
Device managementioctl
Informationgetpid, time
Communicationpipe, socket, shmget

System calls are expensive compared to normal function calls because of the mode switch and register saving, which is why libraries batch work (for example, buffered I/O in printf).

Interrupt

An interrupt is a signal that makes the CPU pause its current work and run an Interrupt Service Routine (ISR).

  • Hardware interrupt: from a device (keyboard press, disk finished, timer tick).
  • Software interrupt / trap: raised by an instruction, either intentionally (system call) or due to an error (divide by zero, page fault). Error traps are also called exceptions.

Steps: CPU finishes the current instruction, saves state (program counter, registers), looks up the handler in the interrupt vector table, runs the ISR, then restores state and resumes.

The timer interrupt is what makes preemptive scheduling possible: it lets the OS regain control even if a process never gives up the CPU.

Polling vs interrupts

  • Polling: CPU repeatedly checks a device status. Simple but wastes cycles.
  • Interrupts: device notifies the CPU when ready. Efficient for slow or infrequent events.

Booting

  1. Power on: CPU starts executing firmware (BIOS or UEFI) from ROM.
  2. Firmware runs POST (power-on self test) and finds a boot device.
  3. The bootloader (GRUB, Windows Boot Manager) loads the kernel into memory.
  4. The kernel initializes hardware, memory management and drivers, mounts the root file system.
  5. The first user process starts (init or systemd, PID 1), which launches everything else.

Quick revision

  • OS = resource manager + extended machine.
  • Monolithic: fast, less isolated. Microkernel: isolated, slower.
  • System calls are the only path from user mode to kernel mode.
  • Interrupts let devices and the timer take control back from running code.