Operating Systems - Complete Guide for Competitive Exams

What is an Operating System?

An Operating System (OS) is system software that acts as an intermediary between computer hardware and the user. It manages computer hardware resources and provides common services for computer programs.

The operating system is the most important software that runs on a computer. It manages the computer's memory, processes, and all of its software and hardware.

Key Functions of an Operating System

Primary Functions of an OS

  1. Process Management: Creation, scheduling, and termination of processes
  2. Memory Management: Allocation and deallocation of memory space
  3. File System Management: Organization, storage, and retrieval of data
  4. Device Management: Control of all input/output devices
  5. Security and Protection: Preventing unauthorized access to system resources
  6. User Interface: Providing interface between user and hardware

Types of Operating Systems

Batch OS

Processes similar jobs in batches. No direct user interaction.

Example: IBM's OS/360

Time-Sharing OS

Multiple users can use the system simultaneously.

Example: UNIX

Distributed OS

Manages a group of independent computers as a single system.

Example: LOCUS

Network OS

Manages network resources and provides services to computers on network.

Example: Windows Server

Real-Time OS

Processes data as it comes in, typically within a time constraint.

Example: VxWorks

Mobile OS

Designed specifically for mobile devices like smartphones and tablets.

Example: Android, iOS

Process Management

What is a Process?

A process is a program in execution. It includes the program code and its current activity.

Process States

  • New: Process is being created
  • Ready: Process is waiting to be assigned to a processor
  • Running: Instructions are being executed
  • Waiting: Process is waiting for some event to occur
  • Terminated: Process has finished execution

Process Control Block (PCB)

PCB is a data structure that contains information about the process:

  • Process State
  • Program Counter
  • CPU Registers
  • CPU Scheduling Information
  • Memory Management Information
  • Accounting Information
  • I/O Status Information

CPU Scheduling

CPU scheduling is the process of selecting which process runs when multiple processes are ready to execute.

Scheduling Algorithm Description Advantages Disadvantages
First-Come, First-Served (FCFS) Processes are executed in order of arrival Simple to implement Poor performance, convoy effect
Shortest Job First (SJF) Process with smallest execution time gets CPU first Minimizes average waiting time Difficult to predict execution time
Priority Scheduling Process with highest priority executes first Important processes get attention Starvation of low priority processes
Round Robin (RR) Each process gets a small time slot (quantum) Fair allocation, good response time Performance depends on quantum size
Multilevel Queue Multiple queues with different priorities Flexible, suitable for complex systems Complex implementation

Memory Management

Memory Hierarchy

  • Registers
  • Cache Memory
  • Main Memory (RAM)
  • Secondary Storage (HDD/SSD)

Memory Allocation Techniques

Contiguous Memory Allocation

  • Single Partition: Entire memory for one process
  • Multiple Partition: Memory divided into multiple partitions

Non-Contiguous Memory Allocation

  • Paging: Memory divided into fixed-size pages
  • Segmentation: Memory divided into variable-size segments

Virtual Memory

Virtual memory is a technique that allows the execution of processes that may not be completely in memory.

Paging in Virtual Memory

Process is divided into fixed-size blocks called pages, and memory is divided into fixed-size blocks called frames.

Page Replacement Algorithms

  • FIFO (First-In-First-Out): Replace the oldest page
  • LRU (Least Recently Used): Replace the page not used for longest time
  • Optimal: Replace the page that will not be used for longest time (theoretical)

Deadlocks

What is a Deadlock?

A deadlock is a situation where a set of processes are blocked because each process is holding a resource and waiting for another resource acquired by some other process.

Necessary Conditions for Deadlock

  1. Mutual Exclusion: At least one resource must be held in non-sharable mode
  2. Hold and Wait: Process holding at least one resource is waiting for additional resources
  3. No Preemption: Resources cannot be preempted
  4. Circular Wait: Circular chain of processes where each process is waiting for a resource held by next process

Deadlock Handling Methods

  • Deadlock Prevention: Ensure that at least one necessary condition cannot hold
  • Deadlock Avoidance: Use algorithms like Banker's Algorithm to avoid unsafe states
  • Deadlock Detection and Recovery: Detect deadlock and recover by aborting processes or preempting resources
  • Ignore Deadlock: Pretend deadlocks never occur (used by most OS including Windows and UNIX)

File System Management

File System Concepts

  • File: Collection of related information
  • Directory: Structure containing list of files and subdirectories
  • File Attributes: Name, type, location, size, protection, time/date

File Allocation Methods

  • Contiguous Allocation: Each file occupies contiguous disk blocks
  • Linked Allocation: Each file is a linked list of disk blocks
  • Indexed Allocation: All pointers brought together into index block

Disk Scheduling Algorithms

  • FCFS (First-Come-First-Served): Requests served in order of arrival
  • SSTF (Shortest Seek Time First): Serve request with minimum seek time
  • SCAN (Elevator Algorithm): Disk arm moves in one direction serving requests
  • C-SCAN (Circular SCAN): Similar to SCAN but returns to start after reaching end
  • LOOK: Similar to SCAN but reverses direction at last request
  • C-LOOK: Similar to C-SCAN but reverses direction at last request

Popular Operating Systems

Operating System Type Developer Key Features
Windows Proprietary Microsoft User-friendly GUI, extensive software support
Linux Open Source Linus Torvalds & Community Stable, secure, highly customizable
macOS Proprietary Apple Sleek UI, good for creative work
UNIX Proprietary AT&T Bell Labs Multi-user, multitasking, portable
Android Open Source Google Mobile OS, based on Linux kernel
iOS Proprietary Apple Mobile OS, secure, optimized for Apple devices

Exam Preparation Tips

  • Understand the different types of operating systems and their characteristics
  • Memorize process states and transitions between them
  • Practice CPU scheduling algorithms with examples
  • Learn the four necessary conditions for deadlock and handling methods
  • Understand memory management techniques including paging and segmentation
  • Be familiar with different file allocation methods and disk scheduling algorithms
  • Know the differences between popular operating systems
  • Practice numerical problems on scheduling algorithms and page replacement

Important OS Concepts

Kernel

The core component of an operating system that manages system resources and communication between hardware and software components.

System Calls

Programmatic way in which a computer program requests a service from the kernel of the operating system.

Interrupts

Signals sent to the processor by hardware or software indicating an event that needs immediate attention.

Threads

Lightweight processes that can run concurrently within the same process, sharing the same memory space.

Semaphores

Synchronization tool used to control access to common resources by multiple processes in a concurrent system.