Operating system key concepts explained

Operating Systems (OS) is a core BSCS course and a favourite topic in exams and job interviews. This guide explains the key concepts (processes, threads, CPU scheduling, deadlock, memory management and virtual memory) in simple words with examples.

What Is an Operating System?

An operating system is system software that manages hardware and provides services to programs and users. It sits between applications and hardware. Examples: Windows, Linux, macOS, Android and iOS.

Main functions: process management, memory management, file management, device (I/O) management, security and providing a user interface.

Types of Operating Systems

  • Batch OS: jobs are grouped and run one after another without user interaction.
  • Multiprogramming / multitasking OS: several programs are kept in memory and the CPU switches between them.
  • Time-sharing OS: each user or task gets a small time slice, giving the feeling of simultaneous use.
  • Real-time OS: must respond within strict time limits (e.g. medical devices, car airbags).
  • Distributed OS: manages a group of networked computers as one system.

Process and Process States

A program is passive code stored on disk; a process is a program in execution. Each process has a Process Control Block (PCB) storing its ID, state, program counter, registers and memory information.

Process states: New → Ready → Running → Waiting (blocked) → Ready … → Terminated.

Process vs Thread

ProcessThread
Independent program in executionSmallest unit of execution inside a process
Has its own memory spaceShares memory with other threads of the same process
Creating and switching is slowerLighter and faster to create and switch

CPU Scheduling Algorithms

  • FCFS (First Come, First Served): simple, but short jobs may wait behind long ones (convoy effect).
  • SJF (Shortest Job First): gives the minimum average waiting time, but long jobs can starve.
  • Priority scheduling: highest priority runs first; aging prevents starvation.
  • Round Robin (RR): each process gets a fixed time quantum; fair and used in time-sharing systems.

Worked Example: FCFS

Processes arrive at time 0 with burst times P1 = 5, P2 = 3, P3 = 2.

  • Waiting times: P1 = 0, P2 = 5, P3 = 8 → average = (0 + 5 + 8) ÷ 3 = 4.33
  • Turnaround times: P1 = 5, P2 = 8, P3 = 10 → average = 7.67

With SJF the order is P3, P2, P1: waiting times 0, 2, 5 → average = 2.33, which shows why SJF reduces waiting time.

Deadlock

A deadlock happens when processes wait for each other forever. It can occur only if all four Coffman conditions hold at the same time:

  1. Mutual exclusion: a resource can be used by only one process at a time.
  2. Hold and wait: a process holds one resource while waiting for another.
  3. No preemption: resources cannot be taken away by force.
  4. Circular wait: a cycle of processes each waits for the next.

Handling methods: prevention (break a condition), avoidance (Banker's algorithm), detection and recovery, or ignoring it (the "ostrich" approach).

Memory Management

  • Paging: memory is divided into fixed-size frames and processes into pages; removes external fragmentation.
  • Segmentation: memory is divided into variable-size logical segments (code, data, stack).
  • Fragmentation: internal = unused space inside an allocated block; external = free space split into small unusable pieces.

Virtual Memory and Page Replacement

Virtual memory lets a program run even if it is larger than physical RAM by keeping only the needed pages in memory. When a needed page is not in RAM, a page fault occurs and the OS loads it from disk. Page replacement algorithms decide which page to remove: FIFO, LRU (Least Recently Used) and Optimal. Too many page faults causes thrashing.

Synchronisation

When processes share data, a critical section must be protected so only one runs it at a time. Tools include mutex locks, semaphores and monitors. Classic problems: producer-consumer, readers-writers and dining philosophers.

FAQ

What is a context switch?

Saving the state of the running process and loading the state of the next one so the CPU can switch between them.

Which scheduling algorithm is best?

There is no single best one. SJF minimises average waiting time, Round Robin is fairest for interactive systems, and real systems often combine methods.

Test your basics with the free computer basics MCQ test and see more study guides.


0 comments:

Post a Comment

 
Top