What is an Operating System (OS)?
Definition: An Operating System is a software that acts as an intermediary between computer hardware and the computer user. It manages hardware resources and provides common services for computer programs.
An operating system is the backbone of a computer system, managing hardware resources and providing a platform for software to run. Understanding its various components, such as process management, memory management, file systems, and security, is essential for developing a strong foundation in computer science and programming.
Functions of an OS:
Process Management: Managing processes, including the execution, scheduling, and termination of processes.
Memory Management: Handling the allocation and deallocation of memory to different processes.
File System Management: Managing files, directories, and storage devices.
Device Management: Managing I/O devices and communication between the computer and external hardware.
Security and Access Control: Ensuring that the system is protected from unauthorized access and providing user authentication.
Types of Operating Systems
Batch Operating System: Jobs are processed in batches without interaction between the user and the computer.
Multiprogramming Operating System: Multiple programs are loaded into memory and executed simultaneously.
Time-Sharing Operating System: Multiple users can interact with the system concurrently by sharing the system's time.
Real-Time Operating System (RTOS): Designed for systems that require immediate processing of inputs and outputs.
Distributed Operating System: A collection of independent computers that appear to the user as a single system.
Operating System Structure
Monolithic Structure: The entire OS runs as a single program in kernel mode.
Layered Structure: OS is divided into layers, each with specific functions. Layer 0 is the hardware, and higher layers provide more abstract services.
Microkernel Structure: The kernel provides minimal services like memory management and inter-process communication, and other services are provided by user-level programs.
Client-Server Model: The OS is split into two components, the client (requester) and the server (provider).
Process Management
What is a Process?
A process is a program in execution. It consists of the program code, current activity, and resources assigned by the operating system.
Process States
New: The process is being created.
Ready: The process is loaded and waiting for CPU time.
Running: The process is currently being executed by the CPU.
Waiting/Blocked: The process is waiting for an event (like I/O).
Terminated: The process has finished its execution.
Process Control Block (PCB)
Contains information about each process such as:
Process State
Program Counter: The address of the next instruction to execute.
CPU Registers: The current values of registers for the process.
Memory Management Information: Information about the allocated memory.
Accounting Information: Includes information such as process IDs and execution time.
Process Scheduling
Memory Management
Memory Hierarchy
Memory Management Techniques
Contiguous Memory Allocation: Each process is allocated a single contiguous block of memory.
Paging: Divides memory into fixed-size pages, and processes are divided into pages that can be loaded into memory.
Segmentation: Divides memory into segments of different sizes based on logical divisions like functions and data.
Virtual Memory
Virtual memory allows processes to access more memory than is physically available by using disk space as an extension of RAM.
Page Fault: Occurs when a program accesses a page not currently in memory.
Demand Paging: Pages are loaded into memory only when needed.
File System Management
What is a File?
A file is a collection of data stored in a specific format. It can represent documents, images, programs, or databases.
File System Structure
File Types: Text files, binary files, directory files.
File Operations: Create, read, write, delete, open, close.
File Attributes: Name, size, type, location, access permissions.
File Organization
Contiguous Allocation: Files are stored in contiguous blocks of memory.
Linked Allocation: Files are stored in scattered blocks, each block containing a pointer to the next.
Indexed Allocation: Uses an index table to keep track of the blocks used by a file.
Directory Structure
Single-Level Directory: All files are stored in a single directory.
Two-Level Directory: Each user has a separate directory.
Hierarchical Directory: Directories are organized in a tree structure.
I/O System Management
Input and Output Devices
Input devices: Keyboard, mouse, scanner.
Output devices: Monitor, printer, speaker.
I/O System Organization
I/O Devices are managed by the OS through device drivers that act as intermediaries between the hardware and the software.
Interrupts: The mechanism by which the CPU is alerted to the need for attention from an I/O device.
I/O Scheduling
I/O Scheduling Algorithms:
FCFS (First-Come, First-Served): Services requests in the order they arrive.
SSTF (Shortest Seek Time First): The request with the shortest seek time is serviced first.
SCAN: The disk arm moves in one direction, servicing all requests, then reverses direction when it reaches the end.
Security and Protection
Security
Security refers to the measures taken to protect the system from unauthorized access, tampering, or theft.
Authentication: The process of verifying the identity of users.
Encryption: Transforming data into a secure format to prevent unauthorized access.
Protection
Protection refers to the mechanisms that prevent unauthorized access or misuse of system resources.
Access Control: Permissions and policies that restrict access to resources.
Access Matrix: A model that specifies the permissions for different users on different resources.