Operating System Principles and Process Scheduling

Classified in Computers

Written on in with a size of 810.17 KB

Core Objectives of an Operating System

  • Convenience: The OS makes the computer more convenient to use by providing an interface between the user and the hardware. It allows users to execute programs easily without knowing low-level hardware details.
  • Efficiency: The OS manages resources like CPU, memory, and I/O efficiently to optimize performance. It ensures that resources are utilized effectively, reducing idle time and maximizing throughput.
  • Ability to Evolve: The OS is designed to allow the development, testing, and introduction of new system functions without interfering with existing services. This allows the OS to adapt to changing user needs and hardware advancements.

Process Definition and Memory Structure

A process is a program in execution. It is the fundamental unit of work in an operating system.

Structure of a Process in Memory

A process in memory consists of the following sections:

  • Text (Code) Section: Stores the program’s executable code.
  • Data Section: Stores global and static variables.
  • Heap: Used for dynamic memory allocation during runtime.
  • Stack: Stores function calls, local variables, and return addresses.

Process Control Block (PCB) Architecture

A Process Control Block (PCB) is a data structure used by the OS to store process information.

Components of a PCB

  • Process ID: A unique identifier for each process.
  • Process State: The current state (Ready, Running, Waiting, etc.).
  • Program Counter: The address of the next instruction to execute.
  • CPU Registers: Stores the process context during execution.
  • Memory Management Information: Includes base and limit registers or page tables.
  • I/O Status Information: Lists devices allocated to the process.
  • CPU Scheduling Information: Includes process priority and scheduling parameters.

s5cg3jhIdvVPG6t1P0r8BeTb6PVBwFJ8AAAAASUVORK5CYII=

Classification of Operating Systems

  • Batch OS: Jobs are processed in batches without user interaction.
  • Time-Sharing OS: CPU time is shared among multiple users.
  • Distributed OS: Multiple computers work together as one system.
  • Network OS: Manages network resources and allows remote access.
  • Real-Time OS: Ensures strict timing constraints in applications (*ELABORATED ON PG 15).

Kernel Definition and Primary Functions

A kernel is the core component of an OS that manages system resources.

Important Functions of the Kernel

  • Process Management: Handles scheduling and execution.
  • Memory Management: Allocates and deallocates memory.
  • Device Management: Controls I/O devices via drivers.
  • File System Management: Manages file creation, access, and security.

Multilevel Queue (MLQ) Scheduling

Multilevel Queue (MLQ) Scheduling is a CPU scheduling algorithm that divides the ready queue into multiple queues, where each queue has its own priority level and scheduling algorithm. This type of scheduling is used when processes can be classified into different categories that require different scheduling needs.

Why Use Multilevel Queue Scheduling?

Some processes require fast response times, while others need long CPU bursts. Instead of treating all processes the same, MLQ Scheduling organizes them into separate queues based on characteristics like:

  • Foreground (Interactive) vs. Background (Batch) processes
  • System processes vs. User processes
  • CPU-bound vs. I/O-bound processes

System process: The operating system itself has its own process to run, called a system process.

Interactive process: An interactive process includes activities like playing an online game or listening to music (requiring constant interaction).

Batch system: We submit the job to the processor and retrieve the result later.

Student process: Typically, the system process will get the highest priority, and the student process gets the lowest priority.

There are many types of processes; we cannot put them in one queue and get the result efficiently. This problem is resolved by multilevel queue scheduling.

jslrOgdmvQMAAAAASUVORK5CYII=

Multilevel Feedback Queue (MLFQ) Features

The Multilevel Feedback Queue (MLFQ) is an advanced CPU scheduling algorithm that improves upon MLQ Scheduling by allowing processes to move between queues based on their behavior.

Key Features of MLFQ

  • Multiple Queues with Different Priorities: The ready queue is divided into multiple queues, each having a different priority.
  • Dynamic Priority Adjustment: If a process consumes too much CPU time, it is moved to a lower-priority queue. If a process waits too long, its priority is increased (aging) to prevent starvation.
  • Different Scheduling Algorithms per Queue: Higher-priority queues may use Round Robin (RR) for fast response times, while lower-priority queues may use First Come, First Serve (FCFS) for long-running processes.
  • Prevention of Starvation: Since processes can move up in priority over time, no process waits indefinitely.

Criteria for Comparing Scheduling Algorithms

  • CPU Utilization: Measures how effectively the CPU is being used. Higher is better.
  • Turnaround Time: The total time taken from process submission to completion. Lower is better.
  • Waiting Time: The time a process spends in the ready queue waiting for the CPU. Lower is better.

Starvation and Multi-Process Scheduling Issues

Starvation occurs when low-priority processes wait indefinitely while higher-priority processes continue to execute. This happens in priority scheduling and multilevel queue scheduling.

Solution: Aging, where the priority of long-waiting processes is gradually increased.

Multilevel Threads Analysis

ASwVh6nQUVhsAAAAAElFTkSuQmCC

7hpIQmQAAmQAAmQgEwCFDoyabMvEiABEiABEiABqQQodKTiZmckQAIkQAIkQAIyCVDoyKTNvkiABEiABEiABKQSoNCRipudkQAJkAAJkAAJyCRAoSOTNvsiARIgARIgARKQSoBCRypudkYCJEACJEACJCCTAIWOTNrsiwRIgARIgARIQCoBCh2puNkZCZAACZAACZCATAIUOjJpsy8SIAESIAESIAGpBCh0pOJmZyRAAiRAAiRAAjIJUOjIpM2+SIAESIAESIAEpBKg0JGKm52RAAmQAAmQAAnIJEChI5M2+yIBEiABEiABEpBK4H+yOmiRGgyyRwAAAABJRU5ErkJggg==

r192pyIpyzYhj4bSgIkQAIkEFcCCbMjS1xbzcJIgARIgARsSYCiZ8uws9EkQAIkYE8CFD17xp2tJgESIAFbEqDo2TLsbDQJkAAJ2JMARc+ecWerSYAESMCWBCh6tgw7G00CJEAC9iRA0bNn3NlqEiABErAlAYqeLcPORpMACZCAPQlQ9OwZd7aaBEiABGxJ4P8B1dqfbRolo40AAAAASUVORK5CYII=

First Come, First Serve (FCFS) Scheduling

Characteristics

  • Non-preemptive.
  • Simple FIFO (First-In, First-Out) execution.
  • Can cause the convoy effect (long processes delay shorter ones).

Disadvantages

  • Poor response time.
  • Starvation for short jobs.

Comparison Between Processes and Threads

FeatureProcessThread
DefinitionIndependent execution unitSubset of a process
MemorySeparate memory spaceShared memory
Creation TimeHighLow

Levels of System Scheduling

  • Long-Term Scheduler: Controls process admission to the system.
  • Short-Term Scheduler: Chooses which process runs next on the CPU.
  • Medium-Term Scheduler: Swaps processes in and out of memory.

Process State Transition Diagram

A process goes through several states during its execution. The five main states are:

  • New: The process is created but not yet ready for execution.
  • Ready: The process is waiting in the ready queue for the CPU.
  • Running: The process is being executed by the CPU.
  • Waiting (Blocked): The process is waiting for an event (like I/O completion).
  • Terminated: The process has completed execution and is removed from the system.

A5S8S3L1uWyxAAAAAElFTkSuQmCC

In-Depth Analysis of Operating System Types

Batch Operating System

In a batch OS, jobs with similar requirements are grouped and executed together without direct user interaction. Users submit their jobs to the system, and they are processed sequentially. This was commonly used in early computing systems, such as punch card-based processing. Examples: IBM Mainframes, early UNIX batch processing.

Time-Sharing Operating System

Also known as a Multitasking OS, this system allows multiple users to share CPU time. The CPU rapidly switches between tasks, giving each user the illusion of direct access. This improves resource utilization and reduces idle time. Examples: Windows, UNIX, and Linux when configured for multiple users.

Distributed Operating System

In a distributed OS, multiple computers (nodes) work together as a single system. Tasks are distributed across different machines, improving performance and fault tolerance. This type of OS is used in cloud computing and large-scale networks. Examples: Google’s Fuchsia OS, Amoeba OS.

Network Operating System

A network OS is designed to manage network resources and provide services like file sharing, remote access, and communication between computers. It allows multiple computers to work in a coordinated manner over a network. Examples: Microsoft Windows Server, Linux-based server OS (Ubuntu Server, Red Hat Enterprise Linux).

Real-Time Operating System (RTOS)

Designed for applications that require immediate processing with strict timing constraints. Used in embedded systems, robotics, industrial automation, and medical devices.

  • Hard RTOS: Ensures that tasks are completed within a strict deadline (e.g., pacemakers, anti-lock braking systems).
  • Soft RTOS: Deadlines are important but not strictly enforced (e.g., video streaming, gaming).

Examples: VxWorks, QNX, FreeRTOS.

Related entries: