Operating System - Detailed Notes
Introduction to Operating System
An Operating System (OS) is a program that acts as an intermediary between a user of a computer
and the computer hardware.
The main goals of an OS are:
- Execute user programs and make solving problems easier.
- Make the computer system convenient to use.
- Use hardware efficiently.
The computer system consists of four main components:
1. Hardware - CPU, memory, I/O devices
2. Operating System
3. Application Programs - word processors, web browsers, games, etc.
4. Users - people, machines, other computers.
The OS can be considered as a **resource allocator** and a **control program**.
Objectives and Functions of Operating System
**Objectives of an OS:**
- Manage I/O operations and devices
- Make the system convenient and efficient to use
- Hide hardware details from users
- Keep track of resources and manage fair sharing
- Provide a Graphical User Interface (GUI)
- Handle interrupts and errors efficiently.
**Functions of an OS:**
1. **Memory Management** - Track memory usage and allocate/deallocate memory.
2. **Processor Management** - Allocate CPU to processes.
3. **Device Management** - Track and manage I/O devices.
4. **File Management** - Allocate and deallocate files and storage.
5. **Security Management** - Prevent unauthorized access.
6. **Job Accounting/Scheduling** - Track time and resources used by jobs.
7. **Error Detection** - Aid in debugging and error reporting.
8. **Coordination with Software** - Coordinate with compilers, interpreters, etc.
Types of Operating System
Different types of OS are used based on system needs. These include:
1. **Batch Operating System** - Processes jobs in batches without interaction.
2. **Time-Sharing (Multitasking) OS** - Allows multiple tasks to run by allocating CPU time.
3. **Distributed OS** - Systems connected over a network that share resources.
4. **Network OS** - Manages networking tasks and provides remote access to resources.
5. **Real-Time OS** - Ensures tasks meet strict time requirements (e.g., air traffic control systems).
6. **Hard and Soft Real-Time OS** - Differ in time constraints and flexibility in task scheduling.
Process Management
A **process** is a program in execution. The operating system manages processes to ensure
smooth execution.
**Process Life Cycle:**
1. **Creation** - Process is created when a program runs.
2. **Ready** - Process is ready to execute.
3. **Running** - Process is actively running on the CPU.
4. **Waiting** - Process is waiting for an event (e.g., I/O).
5. **Termination** - Process finishes execution or is terminated by the OS.
**Process States:**
- **Running**: Executing on CPU.
- **Ready**: Waiting for CPU time.
- **Sleeping**: Waiting for event.
- **Zombie**: Finished but parent hasn't acknowledged.
- **Dead**: Terminated and removed from memory.
**Scheduling Algorithms:**
1. **FCFS (First-Come-First-Served)** - Runs in order of arrival.
2. **SJF (Shortest Job First)** - Runs shortest tasks first.
3. **Priority Scheduling** - Based on priority.
4. **Round Robin** - Circular scheduling with time slices.
**Inter-Process Communication (IPC):**
- **Pipes**: Unidirectional communication.
- **Sockets**: Bidirectional communication.
- **Shared Memory**: Memory space shared between processes.
- **Message Passing**: Exchanging data via messages.
**System Calls for Process Management:**
- `fork()`: Create a new process.
- `exec()`: Replace current process with a new one.
- `wait()`: Suspend current process until child completes.
- `kill()`: Terminate a process.