This repository provides an overview of essential operating system concepts, including system calls, process synchronization, threads, processes, deadlocks, and disk scheduling. Each section outlines fundamental principles, examples, and explanations of these topics to assist in understanding core OS functionality.
System calls are the interface between a user application and the operating system. They enable user programs to request services from the kernel, such as file manipulation, process control, and communication.
- Types of System Calls:
- Process Control:
fork(),exec(),exit() - File Manipulation:
open(),read(),write(),close() - Device Management:
ioctl(),read(),write() - Information Maintenance:
getpid(),alarm() - Communication:
pipe(),shmget(),msgget()
- Process Control:
Process synchronization ensures that multiple processes or threads can operate in parallel without leading to inconsistent data states. This is essential when processes share resources, as unsynchronized access can lead to data corruption.
- Critical Section Problem: Only one process can execute its critical section at any time to prevent data inconsistency.
- Synchronization Mechanisms:
- Locks: Allow mutual exclusion in the critical section.
- Semaphores: Integer values that are used to solve synchronization problems.
- Monitors: High-level constructs that manage access to shared resources.
Example Problem: The Producer-Consumer Problem, where the producer creates data that the consumer uses, demonstrating the need for proper synchronization to avoid buffer overflow or underflow.
Threads are the smallest units of processing within a process. They enable a process to perform multiple tasks concurrently within the same memory space, increasing application performance by utilizing CPU resources more effectively.
-
Single-threaded vs. Multi-threaded Processes:
- Single-threaded: Only one execution path, sequential processing.
- Multi-threaded: Multiple threads within a process, allowing concurrent execution.
-
Advantages of Threads:
- Efficient CPU usage
- Resource sharing
- Faster context switching than processes
Processes are instances of executing programs, containing program code and its activity. They are managed by the OS, and each process has its own memory space.
-
Process Life Cycle:
- New: The process is being created.
- Ready: The process is ready and waiting to be assigned to a CPU.
- Running: The process is currently being executed.
- Waiting: The process is waiting for some event to occur.
- Terminated: The process has completed its execution.
-
Inter-Process Communication (IPC): Mechanisms like pipes, message queues, and shared memory enable processes to communicate and synchronize actions.
Deadlock occurs when a set of processes are blocked, each waiting for a resource held by another in the set, leading to a cycle of dependencies where none of the processes can proceed.
-
Conditions for Deadlock:
- Mutual Exclusion: Only one process can use a resource at a time.
- Hold and Wait: Processes holding resources can request new ones.
- No Preemption: Resources cannot be forcibly taken from a process.
- Circular Wait: A circular chain of processes each waiting for a resource held by the next.
-
Deadlock Prevention & Avoidance:
- Prevention: Modify system conditions to avoid deadlock.
- Avoidance: Use algorithms like Banker's Algorithm to allocate resources safely.
Disk scheduling is a technique used by the OS to decide the order in which disk I/O requests will be processed, aiming to reduce seek time and improve efficiency.
- Disk Scheduling Algorithms:
- FCFS (First-Come, First-Served): Requests are processed in the order they arrive.
- SSTF (Shortest Seek Time First): Selects the request with the shortest seek time from the current head position.
- SCAN (Elevator Algorithm): The disk arm moves in one direction servicing requests until it reaches the end, then reverses.
- C-SCAN (Circular SCAN): Similar to SCAN but only processes requests in one direction, returning to the beginning when reaching the end.
- LOOK and C-LOOK: Variations of SCAN and C-SCAN that do not go to the end of the disk if there are no further requests.
These topics provide a foundational understanding of operating system principles and mechanisms that allow efficient, safe, and organized execution of processes, threads, and I/O operations. Mastery of these concepts is essential for developing efficient and reliable software systems.