7.5 Introduction to Operating System and Process Management

Operating systems (OS) are essential software that manage computer hardware and provide an interface for users to interact with the system. The OS plays a critical role in multitasking, resource management, and providing a stable environment for applications to run.


1. Evolution of Operating Systems

Operating systems have evolved significantly over time. The evolution can be summarized in the following phases:

  • Early Systems: The earliest systems were single-tasking and did not support multitasking. Users interacted directly with the hardware.

  • Batch Systems: These systems allowed jobs to be executed in batches without user interaction. The system would process jobs in a queue and return the results.

  • Multiprogramming: Multiprogramming allowed multiple programs to run concurrently, improving resource utilization and throughput.

  • Time-Sharing Systems: These systems allowed multiple users to access the computer simultaneously by providing each user with a time slice of the CPU.

  • Distributed Systems: These systems introduced a network of computers that could share resources and communicate.

  • Modern OS: Today’s operating systems support advanced features such as virtual machines, cloud computing, and mobile platforms.


2. Types of Operating Systems

Operating systems can be classified into various types based on their features and functionality:

  • Batch Operating System: Executes a batch of jobs without user interaction.

  • Multiprogramming Operating System: Allows multiple programs to run concurrently.

  • Time-Sharing Operating System: Provides CPU time to multiple users for interactive sessions.

  • Real-Time Operating System (RTOS): Designed for systems that require deterministic response times, such as embedded systems.

  • Distributed Operating System: Manages a collection of independent computers that appear as a single system to users.

  • Network Operating System: Facilitates communication and resource sharing between computers in a network.


3. Operating System Components

The operating system is made up of several key components:

  • Kernel: The core part of the OS responsible for managing system resources such as CPU, memory, and I/O devices.

  • User Interface: The interface through which users interact with the OS, typically a command line or graphical user interface (GUI).

  • File System: Manages files and directories, providing services like storing, organizing, and retrieving data.

  • Device Drivers: Software that enables the OS to interact with hardware devices.

  • Shell: A command interpreter that allows users to execute commands and manage processes.


4. Operating System Structure

The OS can be structured in different ways:

  1. Monolithic Structure

  • What it means: The entire operating system (OS) is built as one big program. All functions like file management, memory management, and device drivers are part of the kernel (the core of the OS).

    • Imagine a single, large machine where all parts are tightly connected.

    • If one part fails, it might affect the entire system.

  • Example: Early operating systems like MS-DOS or UNIX used this structure.

  • Advantages:

    • Fast since everything is tightly integrated.

  • Disadvantages:

    • Hard to fix bugs or add new features without affecting the whole system.


  1. Microkernel Structure

  • What it means: Only the most essential parts of the OS are kept in the kernel (like communication between programs and hardware). All other services, such as file management or drivers, run outside the kernel in user space.

    • Imagine a small engine pulling lightweight compartments (the OS services). If one compartment breaks, others can still work.

  • Example: macOS and QNX use a microkernel structure.

  • Advantages:

    • Easier to maintain and update.

    • If a service crashes, it doesn’t bring down the entire OS.

  • Disadvantages:

    • Slower due to constant communication between the kernel and external services.


  1. Modular Structure

  • What it means: The OS is split into separate, self-contained modules (small programs). These modules can be loaded or unloaded as needed.

    • Imagine a toolkit where you can pick and choose the tools you need.

  • Example: Linux is modular. You can load drivers or add functionality (like network support) without rebooting the system.

  • Advantages:

    • Flexible and customizable.

    • Easier to add new features without modifying the whole OS.

  • Disadvantages:

    • Slightly complex to design compared to a monolithic structure.


  1. Layered Structure

  • What it means: The OS is divided into layers. Each layer performs specific tasks and communicates only with its neighboring layers. The bottom-most layer interacts with hardware, while the top-most layer interacts with the user.

    • Think of it like a cake, where each layer has a distinct flavor (responsibility).

  • Example: The THE Operating System was one of the first systems to use a layered approach.

  • Advantages:

    • Easier to design and debug since layers are independent.

  • Disadvantages:

    • Performance can be slower due to the communication overhead between layers.


5. Operating System Services

Operating systems provide several essential services:

  • Process Management: Creating, scheduling, and terminating processes.

  • Memory Management: Allocating and deallocating memory for processes.

  • File Management: Managing files and directories, including file access, permissions, and storage.

  • Device Management: Managing hardware devices like printers, disks, and network interfaces.

  • Security: Ensuring proper access control, authentication, and authorization.

  • Networking: Managing network connections, communication, and resource sharing.


6. Introduction to Processes

  • Process: A process is a program in execution. It is an active entity with its own resources, such as CPU time, memory, and I/O devices.

  • Process Description: A process is described by attributes such as its process ID, state, program counter, registers, and memory space.

  • Process States: A process can be in one of several states:

    • New: Process is being created.

    • Ready: Process is ready to execute but waiting for the CPU.

    • Running: Process is currently being executed.

    • Blocked: Process is waiting for an event or resource.

    • Terminated: Process has completed execution.


7. Process Control

  • Process Control Block (PCB): A data structure that holds information about a process, such as its state, program counter, and CPU registers.

  • Context Switching: The process of saving the state of a running process and loading the state of the next scheduled process.


8. Threads and Processes

  • Thread: A thread is the smallest unit of execution within a process. A process can have multiple threads, which share the process's resources, such as memory and file handles.

  • Processes and Threads: Threads within a process can run concurrently and share the process's resources. Multi-threading allows more efficient use of system resources.


9. Types of Scheduling

Scheduling is the process of determining which process or thread gets access to the CPU at any given time.

  • Long-Term Scheduling: Decides which processes are admitted to the system for execution.

  • Short-Term Scheduling: Decides which process is to be executed next by the CPU.

  • Medium-Term Scheduling: Decides which processes should be swapped in and out of memory.

Scheduling Algorithms in Operating Systems

Scheduling algorithms are techniques used by an operating system (OS) to decide the order in which processes are executed by the CPU. The goal is to efficiently utilize CPU time while ensuring fairness among processes. Here are the common scheduling algorithms:

  • First-Come, First-Served (FCFS)

    • How it works: Processes are executed in the order they arrive in the ready queue.

      • The first process to arrive is executed first.

    • Example: If processes arrive in this order: P1, P2, P3. Execution order: P1 → P2 → P3.

    • Advantages:

      • Simple to implement.

      • Fair to processes.

    • Disadvantages:

      • Convoy effect: Long processes delay shorter ones.

      • Not suitable for interactive systems.

  • Shortest Job Next (SJN)

    • How it works: The process with the smallest burst time (execution time) is executed first.

      • If two processes have the same burst time, they are scheduled on a first-come, first-served basis.

    • Example: If processes have burst times: P1 (6ms), P2 (2ms), P3 (1ms). Execution order: P3 → P2 → P1.

    • Advantages:

      • Minimizes average waiting time.

    • Disadvantages:

      • Requires knowing burst times in advance (not always possible).

      • Can cause starvation for longer processes.

  • Round Robin (RR)

    • How it works: Each process is assigned a fixed time slice (quantum). Processes are executed for their time slice and then moved to the back of the queue if not completed.

      • Preemptive by nature.

    • Example: If quantum = 2ms and burst times: P1 (5ms), P2 (4ms), P3 (3ms). Execution order: P1 (2ms) → P2 (2ms) → P3 (2ms) → P1 (2ms) → P2 (2ms) → P1 (1ms).

    • Advantages:

      • Good for interactive systems.

      • Ensures fairness.

    • Disadvantages:

      • Performance depends on the quantum size.

      • Too small quantum = too many context switches.

      • Too large quantum = behaves like FCFS.

  • Priority Scheduling

    • How it works: Each process is assigned a priority. The process with the highest priority is executed first.

      • Can be preemptive or non-preemptive.

    • Example: If priorities: P1 (2), P2 (1), P3 (3). Execution order: P3 → P1 → P2 (higher number = higher priority).

    • Advantages:

      • Can prioritize important tasks.

    • Disadvantages:

      • Starvation: Low-priority processes may never execute.

      • Solution: Aging (increase priority of processes waiting too long).

  • Multilevel Queue Scheduling

    • How it works: Processes are divided into multiple queues based on priority or type (e.g., system processes, interactive processes). Each queue has its own scheduling algorithm.

      • Example: System processes → RR, User processes → FCFS.

    • Advantages:

      • Categorizes processes for better management.

    • Disadvantages:

      • Rigid; processes cannot move between queues.

  • Multilevel Feedback Queue Scheduling

    • How it works: Similar to multilevel queue scheduling, but processes can move between queues based on their behavior (e.g., CPU-intensive processes move to lower-priority queues).

    • Advantages:

      • Dynamically adapts to process behavior.

    • Disadvantages:

      • Complex to implement.

  • Summary Table of Algorithms

Algorithm

Preemptive

Key Feature

Use Case

First-Come, First-Served

No

Executes processes in arrival order

Batch systems

Shortest Job Next

No

Shortest burst time first

Non-interactive systems

Round Robin

Yes

Fixed time slice for each process

Interactive systems

Priority Scheduling

Yes/No

Executes processes based on priority

Systems requiring prioritization

Multilevel Queue

Yes/No

Divides processes into multiple queues

Systems with distinct job types

Multilevel Feedback Queue

Yes

Processes can move between queues

Systems needing adaptability

Each scheduling algorithm has its strengths and weaknesses, and the choice depends on the system's requirements (e.g., fairness, response time, throughput).


10. Principles of Concurrency

Concurrency refers to the ability of the operating system to execute multiple processes or threads simultaneously. It ensures that system resources are efficiently used while maintaining correctness and consistency.

  • Concurrency Issues:

    • Race Conditions: Occur when multiple processes or threads access shared data and attempt to change it concurrently, leading to unexpected results.

    • Critical Section: A section of code that accesses shared resources and must be executed by only one process or thread at a time.

    • Mutual Exclusion: Ensures that only one process or thread can access a shared resource at a time.


11. Semaphores and Mutex

  • Semaphores: A semaphore is a signaling mechanism used to control access to a shared resource by multiple threads or processes. It can either allow or block access based on certain conditions.

    • Binary Semaphore (Mutex): A semaphore with two states (0 or 1), used to enforce mutual exclusion with 0 (locked) or 1 (unlocked).

    • Counting Semaphore: A semaphore that counts the number of available resources. It keeps track of multiple resources.

  • Mutex: A mutex is a locking mechanism used to ensure mutual exclusion, allowing only one thread at a time to execute a critical section of code. It manages only one resources at a time.

  • Uses of Semaphore and Mutex

    • Semaphore Use: In a database connection pool where a fixed number of connections are available, a counting semaphore can manage access to the connections.

    • Mutex Use: For a shared log file being updated by multiple threads, a mutex ensures that only one thread writes to the file at a time.

By using semaphores and mutexes appropriately, operating systems and applications can avoid issues like race conditions, deadlocks, and resource contention.


12. Message Passing

Message passing is a mechanism that allows processes to communicate and synchronize their actions by sending and receiving messages. It is widely used in distributed systems and parallel computing to enable inter-process communication (IPC).

Key Concepts

  1. Processes:

    • Independent units of execution that require communication to coordinate their tasks or share data.

  2. Messages:

    • Structured data sent from one process to another, often containing information such as commands, requests, or data payloads.

  3. Communication Channels:

    • The medium or mechanism that facilitates message exchange, such as sockets, pipes, or network links.


Mechanisms of Message Passing

  1. Synchronous Message Passing:

    • The sender waits until the receiver acknowledges receipt of the message.

    • Ensures that both processes are synchronized but may introduce delays.

    • Example: A remote procedure call (RPC) where a client waits for the server's response.

  2. Asynchronous Message Passing:

    • The sender sends a message and continues execution without waiting for acknowledgment.

    • Messages may be stored in a queue until the receiver is ready to process them.

    • Example: Email systems or message queues like RabbitMQ.

  3. Direct Communication:

    • Processes explicitly name each other for communication.

    • Example: send(P, message) and receive(Q, message).

  4. Indirect Communication:

    • Processes communicate via an intermediary (e.g., a mailbox or message queue).

    • Example: A client-server model where clients send requests to a server mailbox.


Advantages of Message Passing

  • Decoupling: Processes remain independent, enhancing modularity and flexibility.

  • Scalability: Suitable for distributed systems with multiple processes or machines.

  • Synchronization: Built-in mechanisms ensure orderly communication.

  • Error Isolation: Failures in one process do not directly affect others.


Disadvantages

  • Overhead: Requires additional resources for message management.

  • Latency: Communication delays can occur, especially in distributed systems.

  • Complexity: Handling failures, deadlocks, or message loss can be challenging.


13. Monitors

Monitors are high-level synchronization constructs that provide a way to safely access shared resources by encapsulating the resource and operations that access it. A monitor guarantees that only one process can execute within the monitor at any time.


14. Classical Problems of Synchronization

Some classic synchronization problems include:

Synchronization problems arise when multiple processes or threads attempt to access shared resources. Classical synchronization problems help illustrate the challenges of achieving proper coordination and mutual exclusion. Here are three key problems:

  • Producer-Consumer Problem

    • Description:

      In this problem, there are two types of processes:

      • Producers: Generate data and place it in a shared buffer.

      • Consumers: Remove and process the data from the buffer.

      The challenge is to ensure the producer does not overwrite the buffer when it is full, and the consumer does not consume from an empty buffer.

    • Solution:

      Use a semaphore or mutex to synchronize access to the shared buffer.

      • Semaphores for counting

        • One semaphore tracks the number of filled slots (full).

        • Another semaphore tracks the number of empty slots (empty).

        • Mutex ensures mutual exclusion while accessing the buffer.

    • Example: A printing queue where multiple producers send jobs, and a single printer (consumer) processes them.

  • Readers-Writers Problem

    • Description:

      This problem involves multiple readers and writers accessing shared data:

      • Readers can read simultaneously since they do not modify the data.

      • Writers require exclusive access to ensure data consistency.

      • The challenge is to balance access:

        • Avoid blocking readers unnecessarily.

        • Prevent writers from being starved (unable to write due to constant reading).

    • Solution:

      • Shared locks for readers and exclusive locks for writers:

        • Use a readers count to track how many readers are accessing the data.

        • Ensure writers can only proceed when no readers are accessing the data.

      • Variations:

        • First Readers-Writers Problem: Writers are prioritized, ensuring no writer is starved.

        • Second Readers-Writers Problem: Readers are prioritized, ensuring no reader waits if data is already being read.

    • Example: A database where multiple users can read records simultaneously, but updates require exclusive access.

  • Dining Philosophers Problem

    • Description:

      • Five philosophers sit around a table, alternating between thinking and eating.

      • There are only five chopsticks (one between each philosopher).

      • A philosopher needs two chopsticks to eat, but they can only pick up one at a time.

      • The challenge is to prevent deadlock (all philosophers picking up one chopstick and waiting indefinitely for the second) and starvation (one philosopher never getting both chopsticks).

    • Solution:

      • Use semaphores or mutexes to manage access to chopsticks.

      • Strategies to avoid deadlock:

        • Limit the number of philosophers allowed to pick up chopsticks simultaneously.

        • Ensure philosophers pick up chopsticks in a specific order.

    • Example: Illustrates synchronization challenges in systems with limited resources, such as printer queues or disk access.


Conclusion

Operating system and process management concepts form the foundation for understanding how modern computing systems handle multiple processes, manage resources, and ensure smooth and efficient operation. Key topics like process management, threads, concurrency, synchronization, and scheduling ensure that systems can perform tasks reliably and without conflicts.

Last updated