Operating System Concepts: Functions, Types, and Processes
What is an Operating System?
An Operating System (OS) is system software that acts as an interface between the user and computer hardware. It manages the hardware and software resources of a computer and provides an environment for running application programs.
Examples: Windows, Linux, macOS, Android, and Unix.
Basic Structure of an OS
User
↓
Application Programs
↓
Operating System
↓
HardwareMajor Functions of an Operating System
- Process Management: The OS manages the creation, execution, scheduling, and termination of processes.
- Memory Management: It manages the main memory (RAM) and allocates or deallocates memory to different processes.
- File Management: It manages files and directories, performing operations such as creating, reading, writing, renaming, and deleting files.
- CPU Management: The OS decides which process will use the CPU and for how long. This is called CPU Scheduling.
- Device Management: It manages input/output devices such as the keyboard, mouse, printer, and monitor with the help of device drivers.
- Security and Protection: It protects data and system resources from unauthorized access using passwords, permissions, and access control.
- User Interface: It provides an interface through which users interact with the computer, such as a GUI (Graphical User Interface) or CLI (Command Line Interface).
- Resource Management: It manages and distributes resources such as CPU, memory, storage, and I/O devices among different programs.
Different Types of Operating Systems
- Batch Operating System: Similar jobs are grouped into batches and executed one after another without direct user interaction.
- Multiprogramming Operating System: Multiple programs are kept in memory simultaneously. When one program waits for I/O, the CPU executes another program.
- Multitasking Operating System: It allows multiple tasks to run seemingly at the same time by rapidly switching the CPU between them.
- Multiprocessing Operating System: It uses two or more processors or CPU cores to execute processes simultaneously.
- Time-Sharing Operating System: CPU time is divided into small units called time slices or time quantum, which are shared among processes or users.
- Real-Time Operating System (RTOS): It provides a response within a specified time limit. It is used in robotics, medical equipment, and industrial control systems.
- Hard Real-Time: Deadlines must be met strictly.
- Soft Real-Time: Small delays can be tolerated.
- Distributed Operating System: It manages multiple interconnected computers and makes them work together as a single system.
- Network Operating System: It manages computers connected through a network and provides services such as file sharing, printer sharing, and network security.
Multiprogramming, Multitasking, and Multiprocessing
1. Multiprogramming
Multiprogramming is a technique in which multiple programs are kept in the main memory at the same time, but the CPU executes one program at a time. When the currently running program waits for an I/O operation, the CPU switches to another program instead of remaining idle.
Main Objective: To maximize CPU utilization.
Example: If process P1 is waiting for data from the disk, the CPU can execute P2 during that time.
Main Memory
┌─────────┐
│ P1 │ ← Waiting for I/O
│ P2 │ ← CPU executes P2
│ P3 │
└─────────┘2. Multitasking
Multitasking is a technique in which the CPU executes multiple tasks seemingly at the same time by rapidly switching between them. Each task gets CPU time for a short period, so the user feels that all tasks are running simultaneously.
Main Objective: To provide quick response and smooth execution of multiple tasks.
Example: A user can listen to music, browse the Internet, and edit a document at the same time.
CPU → Music → Browser → Word → Music → Browser → ...3. Multiprocessing
Multiprocessing is a technique in which a computer system uses two or more processors or CPU cores to execute multiple processes simultaneously.
Main Objective: To increase processing speed, performance, and reliability.
Example: In a multi-core computer, one CPU core may execute a web browser, while another core processes a video at the same time.
Multi-Core CPU
┌───────┬───────┐
│ Core 1│ Core 2│
│Browser│ Video │
└───────┴───────┘
↓ ↓
Simultaneous
ExecutionComparison Table
| Basis | Multiprogramming | Multitasking | Multiprocessing |
|---|---|---|---|
| Meaning | Multiple programs kept in memory | Rapid switching between tasks | Multiple processors execute processes |
| CPU | Usually one CPU | Usually one or more CPUs | Two or more processors/cores |
| Execution | One program at a time per CPU | CPU rapidly switches between tasks | Processes execute simultaneously |
| Main Purpose | Increase CPU utilization | Provide quick response | Increase processing speed |
| Switching | Mainly when a process waits | Frequent switching | Less dependent on switching |
| Example | P1 waits for I/O → CPU executes P2 | Browser + Music + Word | Multi-core CPU running processes |
Understanding Processes and Process States
A process is a program that is currently under execution. A program is a passive set of instructions stored on a disk, whereas a process is an active entity that requires CPU, memory, and other system resources for its execution.
Example: A web browser stored on the disk is a program. When the browser is opened and starts executing, it becomes a process.
States of a Process
During its execution, a process passes through different states:
- New State: A process is being created and the OS prepares it for execution.
- Ready State: The process is in main memory and is waiting for the CPU to be assigned.
- Running State: The instructions of the process are currently being executed by the CPU.
- Waiting / Blocked State: The process waits for an event, such as I/O completion, before it can continue.
- Terminated State: The process has completed its execution or has been stopped by the OS.
Process State Diagram
Process Flow:
New → Ready → Running → Terminated
If the process needs an I/O operation: Running → Waiting → Ready → Running
Process Control Block (PCB)
The Process Control Block (PCB) is a data structure maintained by the Operating System that contains important information about a process. It helps the OS identify, manage, and control execution.
Main Information Stored in PCB:
- Process ID (PID): A unique identification number assigned to the process.
- Process State: Stores the current state (Ready, Running, Waiting, etc.).
- Program Counter: Contains the address of the next instruction to be executed.
- CPU Registers: Stores current values of CPU registers related to the process.
- CPU Scheduling Information: Includes process priority and other scheduling parameters.
- Memory Management Information: Details about the memory allocated to the process.
- I/O Status Information: Lists I/O devices and files being used by the process.
┌───────────────────┐
│ PCB │
├───────────────────┤
│ PID │
│ Process State │
│ Program Counter │
│ CPU Registers │
│ Scheduling Info. │
│ Memory Info. │
│ I/O Info. │
└───────────────────┘Threads: Characteristics and Types
A Thread is the smallest unit of execution within a process. A process may contain one or more threads performing different tasks. Threads of the same process share resources such as memory, code, data, and files, but each thread has its own program counter, registers, and stack.
Example: In a web browser, one thread may handle the UI, another may download files, and another may play a video.
┌────────────────────┐
│ PROCESS │
│ Code, Data, Files │
│ (Shared) │
│ T1 T2 T3 T4 │
└────────────────────┘Characteristics of Threads
- Lightweight: A thread requires fewer resources than a complete process.
- Shared Resources: Threads of the same process share code, data, memory, and open files.
- Independent Execution: Each thread has its own program counter, registers, and stack.
- Fast Communication: Threads communicate easily because they share the same memory space.
- Faster Context Switching: Switching between threads is generally faster than switching between processes.
- Concurrent Execution: Multiple threads can perform different tasks concurrently within the same process.
Types of Threads
- User-Level Thread: Created and managed by a user-level thread library without direct OS kernel involvement.
- Kernel-Level Thread: Directly created, managed, and scheduled by the operating system kernel.
Difference Between Process and Thread
| Basis | Process | Thread |
|---|---|---|
| Meaning | A program under execution | Smallest unit of execution in a process |
| Nature | Heavyweight | Lightweight |
| Memory | Has separate memory space | Shares memory with other threads |
| Resources | Has its own resources | Shares process resources |
| Creation | Comparatively slower | Comparatively faster |
| Communication | More complex | Easier and faster |
| Context Switching | Slower | Faster |
| Failure | Does not affect other processes | Failure may affect the entire process |
Round Robin (RR) CPU Scheduling
Round Robin (RR) is a preemptive CPU scheduling algorithm in which each process is assigned a fixed amount of CPU time called the Time Quantum.
If a process is not completed within the given time quantum, it is moved to the end of the ready queue, and the CPU is allocated to the next process.
Example: Time Quantum = 2 ms
Ready Queue: P1 → P2 → P3
Execution: P1 → P2 → P3 → P1 → P2 → ...
Advantages and Disadvantages
Advantages:
- Fair scheduling for all processes.
- Good response time for interactive systems.
- Prevents CPU monopolization by a single process.
Disadvantages:
- A small time quantum increases context switching overhead.
- A large time quantum makes it behave similarly to First-Come, First-Served (FCFS) scheduling.
English with a size of 117.7 KB