Operating Systems
Operating Systems
LECTURE NOTES
OPERATING SYSTEMS
Course Code: DIT1310
OPERATING SYSTEMS 1
OPERATING SYSTEMS
Operating system is a set of programs that control and supervise the hardware resources of a
computer and provide services to other system software. Examples of operating system
includes; Microsoft Windows 95/98/2000/XP/Vista, Unix, Linux, MS-DOS, novel etc. 215
Functions of operating system (OS)
Resource management– the OS allocates computer resources such as CPU time, main
memory, secondary storage and input/output for use by application program.
Job scheduling – the OS prepares, schedules, controls and monitors tasks submitted for
execution to ensure the most efficient processing.
Memory management – the OS ensures that each program and the data it requires are
allocated adequate space in memory.
Error handling – OS provides the error correction routines to ensure smooth operations within
CPU.
Interrupt handling – OS determines the cause of the interrupt and transfer the control to the
most appropriate programs.
Input/output handling – the OS governs input/output of data and their location, storage and
retrieval.
Communication control and management – the operating system is responsible for managing
various communication devices and provide an environment within which communication
protocol operate. The term protocol refers to the rules that governs system come with
network management utilities that provide external communication by connecting to a
communication systems using interface cable or through wireless interface.
History Of Operating Systems.
The history of operating systems (OS) provides insight into the evolution and development of
these critical software systems over time. Here’s a comprehensive overview:
1. Early Days (1950s - 1960s):
• Batch Processing Systems: Early computers used batch processing, where jobs were
executed in batches without user interaction. Examples include IBM’s IBMs 701 and
650.
• Introduction of Multiprogramming: Systems like IBM’s OS/360 introduced
multiprogramming, allowing multiple jobs to be loaded into memory simultaneously
to improve utilization.
2. Development of UNIX (1960s - 1970s):
• UNIX: Developed at Bell Labs by Ken Thompson, Dennis Ritchie, and others, UNIX
was one of the first operating systems to use a hierarchical file system and support
multitasking and multiuser capabilities. It became highly influential and spawned
many derivatives.
3. Personal Computers Era (1980s - 1990s):
OPERATING SYSTEMS 2
• MS-DOS: Microsoft’s Disk Operating System (MS-DOS) became widely used in
personal computers. It was a command-line-based OS known for its simplicity and
efficiency in managing hardware resources.
• Windows: Microsoft introduced Windows as a graphical user interface (GUI) for MS-
DOS, leading to Windows 95, which was a major milestone in personal computing
with a more advanced GUI and improved multitasking capabilities.
4. Modern Operating Systems (2000s - Present):
• Linux: An open-source UNIX-like OS created by Linus Torvalds. It has become
popular for servers, desktops, and embedded systems due to its flexibility and strong
community support.
• macOS: Apple’s macOS, based on the NeXTSTEP OS and UNIX, is known for its
elegant interface and strong integration with Apple’s hardware and software
ecosystem.
• Android and iOS: Mobile operating systems that have dominated the smartphone and
tablet markets, providing touch-based interfaces and extensive app ecosystems.
5. Emerging Trends:
• Cloud Computing: OSs designed for cloud environments, such as Google’s Chrome
OS and various cloud-based server OSs, are becoming increasingly important as more
computing resources move to the cloud.
• IoT and Edge Computing: Operating systems designed for Internet of Things (IoT)
devices and edge computing are evolving to support a wide range of connected
devices and real-time data processing.
OPERATING SYSTEMS 4
• Advantages:
o Suitable for critical applications where timing is crucial.
• Disadvantages:
o Complex to design and implement.
o Limited multitasking capabilities.
1.4 Distributed Operating Systems
• Definition:
o Manages a group of independent computers and makes them appear to users as
a single coherent system.
• Characteristics:
o Resource Sharing: Resources like files, printers, and processing power are
shared across multiple machines.
o Transparency: The distributed nature is hidden from users.
o Example Systems: Amoeba, Plan 9, Google’s Borg.
• Advantages:
o Improved reliability and availability.
o Scalability and resource efficiency.
• Disadvantages:
o Complex network management.
o Issues with data consistency and security.
2. Based on the Number of Simultaneous Users
2.1 Single-User Operating Systems
• Definition:
o Allows only one user to operate the computer at a time.
• Characteristics:
o Dedicated Resources: All system resources are allocated to one user.
o Simpler Design: Less complex compared to multi-user systems.
o Example Systems: MS-DOS, early versions of macOS.
• Advantages:
o Simpler and less resource-intensive.
• Disadvantages:
OPERATING SYSTEMS 5
o Inefficient use of resources if the user’s tasks do not fully utilize the system.
2.2 Multi-User Operating Systems
• Definition:
o Allows multiple users to use the computer and its resources simultaneously.
• Characteristics:
o Concurrent Access: Multiple users can run programs and access files at the
same time.
o User Management: The OS handles user permissions, authentication, and
resource allocation.
o Example Systems: UNIX, Windows Server, Linux.
• Advantages:
o Efficient resource utilization.
o Suitable for environments like servers and mainframes.
• Disadvantages:
o More complex security and resource management.
o Higher chances of performance degradation under heavy load.
3. Based on the Number of Simultaneous Tasks
3.1 Single-Tasking Operating Systems
• Definition:
o Can run only one task or program at a time.
• Characteristics:
o Dedicated Execution: The CPU executes one task until completion before
moving to the next.
o Simpler Design: Less overhead in managing resources.
o Example Systems: MS-DOS.
• Advantages:
o Simple and fast for basic tasks.
• Disadvantages:
o Inefficient for modern computing needs where multitasking is expected.
3.2 Multitasking Operating Systems
• Definition:
OPERATING SYSTEMS 6
o Can execute multiple tasks or programs simultaneously.
• Types:
o Preemptive Multitasking: The OS decides when to switch tasks based on
priority (e.g., Windows, UNIX).
o Cooperative Multitasking: Each task controls the CPU until it voluntarily
yields control (e.g., early versions of macOS).
• Characteristics:
o Task Scheduling: The OS schedules tasks to maximize CPU usage.
o Concurrency: Multiple processes or threads can run concurrently.
o Example Systems: Windows, Linux, macOS.
• Advantages:
o Efficient use of CPU and system resources.
• Disadvantages:
o Increased complexity in managing tasks and resources.
o Potential for resource conflicts (e.g., deadlock).
4. Based on System Architecture
4.1 Monolithic Operating Systems
• Definition:
o The entire operating system works in the kernel space and is tightly integrated.
• Characteristics:
o Single Large Kernel: All OS functions (file management, process scheduling,
etc.) run in a single, large block of code in kernel mode.
o Fast Performance: Minimal context switching and overhead.
o Example Systems: UNIX, Linux.
• Advantages:
o High performance due to less overhead.
• Disadvantages:
o Harder to debug and maintain due to the complexity and integration of
functions.
4.2 Microkernel Operating Systems
• Definition:
OPERATING SYSTEMS 7
o The core functionality (such as IPC, basic scheduling) is provided by a small
kernel, while other services run in user space.
• Characteristics:
o Minimal Kernel: Only essential services run in kernel mode.
o Modular Design: Other services (e.g., device drivers, file systems) run in user
mode.
o Example Systems: MINIX, QNX.
• Advantages:
o Greater security and stability due to isolation of services.
o Easier to extend and modify.
• Disadvantages:
o Potentially slower due to the overhead of user-kernel mode transitions.
4.3 Hybrid Operating Systems
• Definition:
o Combines elements of both monolithic and microkernel architectures.
• Characteristics:
o Modular Kernel: Core functions run in the kernel space, but additional
modules or services can be loaded dynamically.
o Balance: Tries to achieve a balance between performance and modularity.
o Example Systems: Windows NT, macOS.
• Advantages:
o Flexibility and extensibility.
o Better performance than pure microkernel systems.
• Disadvantages:
o More complex design and implementation.
5. Based on Specialization
5.1 Embedded Operating Systems
• Definition:
o Designed to operate within embedded systems, which are specialized
computing devices.
• Characteristics:
OPERATING SYSTEMS 8
o Real-Time Capabilities: Often includes RTOS features to manage time-critical
tasks.
o Resource Constraints: Designed to work with limited memory, processing
power, and energy.
o Example Systems: Embedded Linux, VxWorks, FreeRTOS.
• Advantages:
o Optimized for specific tasks and environments.
o Efficient resource management.
• Disadvantages:
o Limited in scope and functionality.
o Harder to modify or upgrade.
5.2 Network Operating Systems
• Definition:
o Facilitates networked computing by providing services to computers
connected in a network.
• Characteristics:
o Resource Sharing: Enables sharing of files, printers, and other resources over a
network.
o User Management: Handles multiple users across different machines.
o Example Systems: Novell NetWare, Windows Server, UNIX/Linux in server
mode.
• Advantages:
o Centralized control and management.
o Supports collaborative work environments.
• Disadvantages:
o Complex to configure and manage.
o Security vulnerabilities in a networked environment.
5.3 Distributed Operating Systems
• Definition:
o Manages a collection of independent computers and makes them appear as a
single unified system.
• Characteristics:
OPERATING SYSTEMS 9
o Transparency: Users and applications perceive the distributed resources as a
single coherent system.
o Resource Sharing: Files, processing power, and other resources are shared
across multiple systems.
o Example Systems: Amoeba, Plan 9, Google’s Borg.
• Advantages:
o Enhanced reliability and fault tolerance.
o Scalability to handle increasing loads.
• Disadvantages:
o Complex to implement and maintain.
o Issues with data consistency and coordination.
OPERATING SYSTEMS 10
2.1 Definition:
• A GUI allows users to interact with the computer through graphical elements such as
windows, icons, buttons, and menus. It is designed to be intuitive and user-friendly.
2.2 Characteristics:
• Graphical Elements: Uses visual components like icons, windows, and menus.
• Ease of Use: Provides a more accessible and user-friendly experience compared to
CLI.
• WYSIWYG: What You See Is What You Get, allowing for visual manipulation of
documents and applications.
2.3 Examples:
• Microsoft Windows
• macOS
• GNOME and KDE (Linux Desktop Environments)
OPERATING SYSTEMS 11
• Voice-Based: Users give commands or provide input through spoken language.
• Hands-Free: Useful for situations where hands-free interaction is preferred or
necessary.
4.3 Examples:
• Amazon Alexa
• Google Assistant
• Apple Siri
1. Monolithic Architecture
1.1 Definition:
• In a monolithic architecture, the operating system is designed as a single, large kernel
that includes all the essential components and services. All system services, including
device drivers, file systems, and process management, run in kernel mode.
1.2 Characteristics:
• Single Large Kernel: The OS kernel is a monolithic block of code.
• Direct Communication: Components of the OS can communicate directly with each
other.
OPERATING SYSTEMS 12
• Integrated Services: Device drivers, system calls, and core functionalities are tightly
integrated into the kernel.
1.3 Advantages:
• Performance: Direct communication between components can lead to high
performance and efficiency.
• Simplicity: The design is straightforward since all functionalities are within one large
module.
1.4 Disadvantages:
• Complexity: The monolithic kernel can become complex and hard to manage as it
grows.
• Stability: A failure in one part of the kernel can affect the entire system, leading to
potential stability issues.
• Maintenance: Modifying or extending functionality can be challenging due to the
tight coupling of components.
1.5 Examples:
• Linux (traditional monolithic design)
• MS-DOS
2. Microkernel Architecture
2.1 Definition:
• In a microkernel architecture, the kernel is designed to be minimal, containing only
the most fundamental components such as basic scheduling, inter-process
communication (IPC), and low-level hardware management. Other services, including
device drivers, file systems, and network protocols, run in user space as separate
processes.
2.2 Characteristics:
• Minimal Kernel: The microkernel includes only essential functions required for
managing hardware and communication.
• User-Space Services: Non-essential services and components run outside the kernel in
user space.
• Modular Design: Components are modular and can be updated or replaced
independently.
2.3 Advantages:
• Modularity: Easier to maintain and extend due to the separation of services.
OPERATING SYSTEMS 13
• Stability: Faults in user-space services do not crash the entire system; the kernel
remains unaffected.
• Flexibility: Allows for easy adaptation and enhancement of system services without
modifying the kernel.
2.4 Disadvantages:
• Performance Overhead: Communication between user-space services and the
microkernel can introduce performance overhead due to IPC.
• Complex Design: Requires efficient design and management of inter-process
communication and system calls.
2.5 Examples:
• MINIX
• QNX
• Mach (used in macOS and GNU Hurd)
Conclusion
Monolithic and microkernel architectures represent two different approaches to designing
operating systems. Monolithic systems integrate all core functionalities into a single kernel,
leading to high performance but potential complexity and stability issues. Microkernel
systems aim for modularity and flexibility by minimizing the kernel’s responsibilities and
running most services in user space, though they may face performance overhead. Each
architecture has its strengths and trade-offs, influencing the design and functionality of the
operating systems that use them.
Kernel
The kernel is the core component of an operating system (OS) that manages system resources
and facilitates communication between hardware and software. It is responsible for handling
low-level operations and providing essential services to the system.
2. Types of Kernels
2.1 Monolithic Kernels
• Definition: A monolithic kernel includes all essential services and device drivers
within a single large kernel module.
• Characteristics:
o All system services run in kernel mode.
o Direct communication between components.
• Advantages:
o High performance due to direct interactions.
o Simplicity in design.
• Disadvantages:
o Complexity in maintenance and extension.
o Stability risks if any part of the kernel fails.
• Examples:
o Linux (traditional design)
o MS-DOS
2.2 Microkernels
• Definition: A microkernel contains only the most basic functionalities, such as process
scheduling and inter-process communication (IPC). Other services run in user space.
• Characteristics:
o Minimal kernel with essential functions.
o Services run as separate user-space processes.
• Advantages:
o Enhanced modularity and flexibility.
OPERATING SYSTEMS 15
o Better stability as user-space services are isolated.
• Disadvantages:
o Potential performance overhead due to IPC.
o More complex design and management.
• Examples:
o MINIX
o QNX
o Mach (used in macOS)
2.3 Hybrid Kernels
• Definition: Hybrid kernels combine elements of both monolithic and microkernel
architectures, incorporating some services within the kernel while running others in
user space.
• Characteristics:
o Mixes features of monolithic and microkernel designs.
o Aims to balance performance and modularity.
• Advantages:
o Combines the benefits of both architectures.
o More stable and flexible than monolithic kernels.
• Disadvantages:
o Increased complexity due to hybrid nature.
o Potential overhead from combining different approaches.
• Examples:
o Windows NT (modern versions)
o macOS (XNU kernel)
OPERATING SYSTEMS 16
• Virtual Memory: Manages virtual address space and paging.
3.3 Device Management
• Drivers: Interfaces with hardware devices.
• I/O Operations: Handles input and output operations.
3.4 System Calls
• API: Provides an interface for applications to request kernel services.
3.5 Security and Protection
• Access Control: Manages permissions and access to resources.
• Isolation: Ensures processes are isolated and cannot interfere with each other.
OPERATING SYSTEMS 17
• Simplified Operations: Easy to automate and manage large volumes of similar jobs.
1.5 Disadvantages:
• No User Interaction: Lack of real-time user interaction means users must wait until
the entire batch is processed.
• Complex Debugging: Errors in batch jobs can be difficult to debug as they are
processed in sequence.
OPERATING SYSTEMS 18
• Distributed operating systems manage a group of independent computers and make
them appear as a single computer to users. The system coordinates the operation of
multiple machines working on different parts of a task.
3.2 Key Features:
• Resource Sharing: Resources such as files and printers are shared across multiple
systems.
• Transparency: Users interact with the system as if it were a single unit, even though it
consists of multiple computers.
• Scalability: The system can easily be expanded by adding more machines.
3.3 Examples:
• Amoeba
• LOCUS
• Microsoft Azure
3.4 Advantages:
• Resource Sharing: Efficient use of resources across a network.
• Fault Tolerance: System can continue functioning even if one or more machines fail.
3.5 Disadvantages:
• Complexity: Management and coordination of multiple machines can be complex.
• Security and Privacy: Distributed systems are vulnerable to security breaches due to
the networked nature.
OPERATING SYSTEMS 19
• Hard Real-Time: Systems where missing a deadline is catastrophic (e.g., pacemakers,
airbag systems).
• Soft Real-Time: Systems where deadlines are important but not critical (e.g.,
multimedia systems).
4.4 Examples:
• VxWorks
• RTLinux
• QNX
4.5 Advantages:
• Reliability: Predictable and reliable performance for critical applications.
• Efficiency: Optimized for real-time tasks, ensuring timely and efficient processing.
4.6 Disadvantages:
• Complex Development: Developing RTOS applications can be challenging due to
strict timing constraints.
• Limited Multitasking: RTOS may limit multitasking capabilities to ensure critical
tasks meet deadlines.
OPERATING SYSTEMS 20
5.4 Advantages:
• Efficiency: Optimized for the specific device, making efficient use of limited
resources.
• Reliability: Designed for stability and reliability in the specific environment.
5.5 Disadvantages:
• Limited Flexibility: Generally limited to specific tasks and may not be adaptable to
other uses.
• Dependency on Hardware: Often closely tied to the hardware, making it difficult to
transfer to other platforms.
OPERATING SYSTEMS 21
7.1 Definition:
• Mobile operating systems are designed specifically for mobile devices such as
smartphones and tablets. They are optimized for touchscreen interfaces and mobile
hardware.
7.2 Key Features:
• Touch Interface: Designed to be used with touch screens.
• App Store Ecosystem: Supports downloading and managing apps via an app store.
• Connectivity: Built-in features for cellular, Wi-Fi, Bluetooth, and other connectivity
options.
7.3 Examples:
• Android
• iOS
• Windows Phone (Discontinued)
7.4 Advantages:
• User-Friendly: Intuitive interfaces designed for easy use on mobile devices.
• Large Ecosystem: Extensive app availability and developer support.
7.5 Disadvantages:
• Hardware Limitations: Mobile devices have less processing power and memory
compared to PCs.
• Security Concerns: Mobile OSs are often targeted by malware due to their widespread
use.
OPERATING SYSTEMS 22
• OpenStack
• VMware ESXi
• Amazon Web Services (AWS) EC2
8.4 Advantages:
• On-Demand Resources: Provides resources as needed, optimizing costs and
efficiency.
• Flexibility: Easily adapts to changing workloads and business needs.
8.5 Disadvantages:
• Security Risks: Cloud environments are prone to security breaches if not properly
managed.
• Dependency on Internet: Requires a stable internet connection for optimal
performance.
Operating Systems Structure
The structure of an operating system (OS) refers to how its various components are organized
and interact with each other to manage hardware resources and provide services to
applications. The structure can significantly impact the OS's performance, flexibility, and
complexity. Here’s a detailed overview of common OS structures:
1. Monolithic Structure
1.1 Definition:
• In a monolithic OS structure, the entire operating system is built as a single, large
program running in a single address space (kernel mode). All core functionalities such
as process management, memory management, file systems, and device drivers are
integrated into this single unit.
1.2 Key Components:
• Process Management: Handles process creation, scheduling, and termination.
• Memory Management: Manages memory allocation and deallocation.
• File System: Provides file operations and storage management.
• Device Drivers: Interfaces with hardware devices.
1.3 Advantages:
• Performance: Direct communication between components can lead to high efficiency.
• Simplicity: Easier to design and implement as all functions are part of one large
module.
1.4 Disadvantages:
OPERATING SYSTEMS 23
• Lack of Modularity: Modifying or extending functionality can be difficult.
• Stability and Security Risks: A failure in one part can affect the entire system.
• Complex Debugging: Intertwined components can make debugging challenging.
1.5 Examples:
• Linux (traditional monolithic design)
• MS-DOS
2. Layered Structure
2.1 Definition:
• The layered OS structure organizes the operating system into layers, where each layer
performs a specific set of functions and interacts with the layer directly above and
below it. Each layer only needs to interact with adjacent layers.
2.2 Key Layers:
• Hardware Layer: Includes the physical hardware components.
• Kernel Layer: Manages core functionalities like process management and memory
management.
• System Call Interface: Provides a set of system calls for user-space applications.
• Application Layer: Includes user applications and services.
2.3 Advantages:
• Modularity: Easier to manage and update individual layers without affecting others.
• Isolation: Problems in one layer do not necessarily affect others.
2.4 Disadvantages:
• Performance Overhead: Layered architecture can introduce overhead due to the
abstraction layers.
• Complexity: Design and implementation can be more complex due to the multiple
layers.
2.5 Examples:
• Windows NT (modern versions)
3. Microkernel Structure
3.1 Definition:
OPERATING SYSTEMS 24
• In a microkernel structure, only the most fundamental functionalities (such as inter-
process communication and basic scheduling) are included in the kernel. Other
services like device drivers, file systems, and network protocols run in user space as
separate processes.
3.2 Key Components:
• Microkernel: Manages low-level operations and communication between user-space
processes.
• User-Space Services: Includes drivers, file systems, and network protocols.
3.3 Advantages:
• Modularity: Allows easy modification and extension of services.
• Fault Isolation: Crashes or bugs in user-space services do not bring down the entire
system.
• Flexibility: Easier to adapt and expand.
3.4 Disadvantages:
• Performance Overhead: Communication between user-space processes and the
microkernel can introduce latency.
• Complex Design: Requires efficient inter-process communication and careful design.
3.5 Examples:
• MINIX
• QNX
• Mach (used in macOS and GNU Hurd)
4. Hybrid Structure
4.1 Definition:
• A hybrid OS structure combines elements of both monolithic and microkernel
designs. It incorporates some services in the kernel space for performance reasons
while running other services in user space for modularity and stability.
4.2 Key Components:
• Kernel Space: Contains core functionalities that require high performance.
• User Space: Hosts additional services and drivers to ensure modularity and
extensibility.
4.3 Advantages:
• Balanced Performance: Combines the performance benefits of monolithic kernels
with the modularity of microkernels.
OPERATING SYSTEMS 25
• Improved Stability: More stable than monolithic systems due to isolated user-space
services.
4.4 Disadvantages:
• Complexity: More complex than purely monolithic or microkernel designs due to the
mix of both approaches.
• Potential Overhead: Some overhead may still exist due to the combination of kernel
and user-space services.
4.5 Examples:
• Windows NT (modern versions)
• macOS (using XNU, which combines Mach microkernel and elements from
FreeBSD)
5. Exokernel Structure
5.1 Definition:
• Exokernels provide only minimal abstractions and allow applications to manage
hardware resources directly. The OS provides a basic interface for hardware access,
and applications are responsible for implementing higher-level abstractions.
5.2 Key Components:
• Exokernel: Manages low-level hardware operations and provides a basic interface for
resource management.
• Library Operating Systems: Implement higher-level abstractions and functionality in
user space.
5.3 Advantages:
• Fine-Grained Control: Applications have more control over hardware resources.
• Customization: Allows for highly customized operating environments based on
specific application needs.
5.4 Disadvantages:
• Complex Development: Application developers need to handle resource management,
which can be complex.
• Limited Abstractions: The OS provides fewer abstractions, which might make
development harder for some applications.
5.5 Examples:
• MIT Exokernel
OPERATING SYSTEMS 26
6. Nano Kernel Structure
6.1 Definition:
• Nano kernels are an even more minimalistic approach than microkernels, containing
only the most essential components, such as interrupt handling and basic resource
management.
6.2 Key Components:
• Nano Kernel: Provides only the most basic functions needed to manage hardware and
interrupts.
• User-Space Services: All other services, such as device drivers and file systems, run
in user space.
6.3 Advantages:
• Minimalistic Design: Extremely lightweight and focused on core functionalities.
• Modularity: Similar benefits of microkernels with an even smaller kernel.
6.4 Disadvantages:
• Increased Complexity for Developers: Requires developers to implement more
functionalities in user space.
• Limited Functionality: Only suitable for systems where minimal functionality is
acceptable.
6.5 Examples:
• Some specialized embedded systems
5. Virtual Machines (VMs)
A Virtual Machine (VM) is an emulation of a computer system that provides the functionality
of a physical computer. Virtual machines are used to run multiple operating systems on a
single physical machine, each operating as if it were running on its own separate hardware.
OPERATING SYSTEMS 27
• Resource Utilization: Improve resource utilization by allowing multiple virtual
systems to run on a single physical system.
• Testing and Development: Facilitate testing and development environments without
requiring additional physical hardware.
OPERATING SYSTEMS 28
• Definition: A virtual machine image is a file or set of files that contain the virtual
machine’s operating system, applications, and data. It is used to create and restore
virtual machines.
• Types:
o Full VM Image: Includes the complete system state, including the OS,
applications, and all data.
o Snapshot: A point-in-time copy of the VM’s state, allowing rollback to a
previous state.
3.3 Guest Operating System
• Definition: The operating system installed and running within a virtual machine. It
functions as if it were running on a physical machine.
• Characteristics: Each VM can run a different guest OS, including different versions or
distributions of operating systems.
OPERATING SYSTEMS 29
5. Challenges and Limitations
5.1 Performance Overhead
• Resource Contention: Multiple VMs sharing the same physical resources can lead to
performance degradation due to resource contention.
• Overhead: Hypervisors introduce some overhead, which can affect the performance of
VMs compared to running directly on physical hardware.
5.2 Complexity
• Management: Managing multiple VMs, including their resource allocation, updates,
and security, can become complex.
• Networking: Networking configurations for VMs can be complex, especially in multi-
VM and multi-network environments.
5.3 Licensing and Cost
• Licensing: Some virtualization platforms and guest operating systems may have
licensing costs associated with them.
• Resource Management: Requires careful planning and management to ensure efficient
use of physical resources.
OPERATING SYSTEMS 30
1. What is a Process?
1.1 Definition:
• A process is an instance of a program in execution. It includes the program code,
current activity, and the state of the program.
1.2 Components of a Process:
• Program Code (Text Section): The actual code to be executed.
• Program Counter: Indicates the next instruction to be executed.
• Process Stack: Contains temporary data like function parameters, return addresses,
and local variables.
• Data Section: Includes global variables and dynamic memory allocations.
• Process Control Block (PCB): Contains information about the process state, program
counter, CPU registers, memory management information, and I/O status.
2. Process States
A process can be in one of the following states:
2.1 New:
• The process is being created.
2.2 Ready:
• The process is loaded into memory and is waiting to be executed by the CPU.
2.3 Running:
• The process is currently being executed by the CPU.
2.4 Waiting (Blocked):
• The process is waiting for an event or I/O operation to complete.
2.5 Terminated:
• The process has finished execution or has been terminated by the OS.
3. Process Scheduling
Process scheduling is the method by which the OS decides which process runs at any
given time. It is vital for multitasking and efficient CPU utilization.
3.1 Schedulers:
OPERATING SYSTEMS 31
• Long-Term Scheduler (Job Scheduler): Decides which processes are admitted to the
system for processing.
• Short-Term Scheduler (CPU Scheduler): Determines which of the ready processes
should be executed next by the CPU.
• Medium-Term Scheduler: Swaps processes in and out of memory to manage the
degree of multiprogramming.
3.2 Scheduling Algorithms:
• First-Come, First-Served (FCFS): Processes are scheduled in the order they arrive.
• Shortest Job Next (SJN): The process with the smallest execution time is selected
next.
• Priority Scheduling: Processes are scheduled based on priority.
• Round Robin (RR): Each process is assigned a fixed time slice, and processes are
scheduled in a cyclic order.
• Multilevel Queue Scheduling: Processes are divided into multiple queues, each with
different priority levels.
• Multilevel Feedback Queue: Processes can move between queues based on their
behavior and execution history.
4. Context Switching
4.1 Definition:
• Context switching is the process of saving the state of a currently running process and
loading the state of the next process to be executed.
4.2 Steps Involved:
• Save the state of the current process in its PCB.
• Update the process state to "waiting" or "ready."
• Load the state of the next process from its PCB.
• Update the process state to "running."
4.3 Overhead:
• Context switching introduces overhead, as it requires time to save and load process
states. Minimizing context switches is crucial for system efficiency.
5. Process Synchronization
OPERATING SYSTEMS 32
In a multitasking environment, processes may need to cooperate or share resources, which
can lead to race conditions and data inconsistency. Process synchronization mechanisms
ensure that processes execute in a safe and predictable manner.
5.1 Critical Section:
• A section of code where shared resources are accessed. Proper synchronization is
required to avoid conflicts.
5.2 Synchronization Mechanisms:
• Semaphores: Integer variables used to solve synchronization problems. They can
signal and wait to ensure mutual exclusion.
• Mutexes: Locks that ensure only one process can access a critical section at a time.
• Monitors: High-level synchronization constructs that manage access to shared
resources.
• Barriers: Synchronization points where processes must wait until all involved
processes reach the barrier.
6. Process Communication
Processes may need to communicate with each other for data sharing and coordination.
6.1 Inter-Process Communication (IPC):
• Shared Memory: Processes share a common memory space for communication.
• Message Passing: Processes communicate by sending and receiving messages.
• Pipes: Unidirectional data channels used for communication between processes.
• Sockets: Network-based communication endpoints for processes on different systems.
• Signals: Notifications sent to processes to inform them of events or conditions.
OPERATING SYSTEMS 33
The process model in operating systems is a conceptual framework that describes how
processes are managed, executed, and interact within a system. It defines how the
operating system abstracts the hardware to create an environment where multiple
processes can run concurrently, ensuring efficient resource utilization and isolation.
OPERATING SYSTEMS 34
o Waiting: The process is waiting for some event (like I/O completion) to occur.
o Termination: The process has finished execution and is being removed from
the system.
OPERATING SYSTEMS 35
• Requires synchronization mechanisms to manage access to shared resources.
5. Process Interaction
5.1 Inter-Process Communication (IPC):
• Shared Memory: Processes communicate by sharing a region of memory.
• Message Passing: Processes send and receive messages through the operating system.
• Pipes, Sockets, Signals: Other mechanisms to facilitate communication between
processes.
5.2 Synchronization:
• Ensures that processes interact with shared resources in a safe manner.
• Avoids race conditions and ensures data consistency.
• Tools include semaphores, mutexes, and monitors.
OPERATING SYSTEMS 36
8. Challenges in Process Management
• Deadlock: Situations where processes are unable to proceed because they are waiting
on each other to release resources.
• Starvation: A process may be perpetually denied resources due to the scheduling
policy.
• Race Conditions: Incorrect behaviour due to the timing of events in concurrent
processes.
Process Scheduling in Operating Systems
Process scheduling is a fundamental aspect of operating systems (OS) that determines the
order in which processes access the CPU and other system resources. Effective
scheduling is crucial for achieving optimal system performance, maximizing CPU
utilization, and ensuring a responsive user experience.
2. Types of Schedulers
The OS uses different types of schedulers to manage processes at various stages of their
lifecycle.
OPERATING SYSTEMS 37
2.1 Long-Term Scheduler (Job Scheduler):
• Decides which processes are admitted into the system for execution.
• Controls the degree of multiprogramming (the number of processes in memory).
• Infrequent execution, as it decides the overall job load.
2.2 Short-Term Scheduler (CPU Scheduler):
• Selects which of the ready processes in the ready queue will be executed next by the
CPU.
• Executes frequently (often every few milliseconds).
• Makes decisions quickly to maintain system responsiveness.
2.3 Medium-Term Scheduler:
• Swaps processes in and out of the memory to optimize CPU and memory usage.
• Works in systems with medium-term scheduling needs, such as swapping to manage
multiprogramming.
3. Scheduling Criteria
When choosing a scheduling algorithm, various criteria are considered:
3.1 CPU Utilization:
• The percentage of time the CPU is active and executing processes.
3.2 Throughput:
• The number of processes completed per unit of time.
3.3 Turnaround Time:
• The total time taken from process submission to completion, including waiting,
execution, and I/O time.
3.4 Waiting Time:
• The total time a process spends in the ready queue.
3.5 Response Time:
• The time from process submission until the first output is produced.
4. Scheduling Algorithms
Several scheduling algorithms are used to decide the order of process execution. Each has
its advantages and disadvantages depending on system requirements.
4.1 First-Come, First-Served (FCFS):
OPERATING SYSTEMS 38
• Processes are executed in the order they arrive in the ready queue.
• Simple to implement but can lead to the convoy effect, where short processes get
stuck waiting behind long processes.
• Non-preemptive: Once a process starts executing, it runs to completion.
4.2 Shortest Job Next (SJN) / Shortest Job First (SJF):
• Processes with the shortest burst time are executed first.
• Optimal for minimizing average waiting time but requires accurate prediction of
process burst times.
• Can be non-preemptive or preemptive (Shortest Remaining Time First - SRTF).
4.3 Priority Scheduling:
• Each process is assigned a priority, and the CPU is allocated to the process with the
highest priority.
• Can be preemptive or non-preemptive.
• Risk of starvation: Low-priority processes may never get executed.
• Aging can be used to gradually increase the priority of processes that wait too long.
4.4 Round Robin (RR):
• Each process is assigned a fixed time slice (quantum), and processes are executed in a
cyclic order.
• Suitable for time-sharing systems as it provides a fair distribution of CPU time.
• The choice of time quantum is crucial: too short leads to excessive context switching;
too long behaves like FCFS.
4.5 Multilevel Queue Scheduling:
• The ready queue is divided into several separate queues based on process priority or
type (e.g., system processes, interactive processes).
• Each queue has its own scheduling algorithm, and there’s a scheduling strategy to
choose between queues.
• Processes do not move between queues.
4.6 Multilevel Feedback Queue:
• Allows processes to move between queues based on their behavior and execution
history.
• Provides flexibility and can adapt to different process requirements.
• Helps in mitigating the drawbacks of strict multilevel queue scheduling.
4.7 Earliest Deadline First (EDF):
OPERATING SYSTEMS 39
• Used in real-time systems, where the process with the earliest deadline is selected for
execution.
• Dynamic priority scheduling: process priorities can change over time.
6. Context Switching
6.1 Definition:
• The process of storing the state of a currently running process and loading the state of
the next process to be executed.
• Necessary for switching the CPU from one process to another.
6.2 Overhead:
• Context switching is resource-intensive as it involves saving and loading registers,
program counters, and memory mappings.
• Excessive context switches can reduce system performance.
7. Performance Considerations
• Choosing the Right Algorithm: The optimal scheduling algorithm depends on the
system's specific requirements and workload characteristics.
• Balancing Criteria: Trade-offs between CPU utilization, throughput, turnaround
time, waiting time, and response time must be balanced.
• System Type: Different systems (e.g., batch systems, interactive systems, real-time
systems) have varying needs that influence the choice of scheduling algorithms.
Deadlocks in Operating Systems
OPERATING SYSTEMS 40
Deadlocks are a critical issue in operating systems where a set of processes is unable to
proceed because each process is waiting for a resource that another process in the set
holds. This situation leads to a standstill, where none of the processes can continue to
execute. Understanding deadlocks, their causes, and how to handle them is crucial for
system stability and resource management.
2. Deadlock Prevention
Deadlock prevention involves ensuring that at least one of the necessary conditions for
deadlock cannot hold. Strategies include:
2.1 Mutual Exclusion:
• Avoid mutual exclusion where possible by allowing resources to be shared if they can
be used concurrently.
• For example, read-only files can be shared among processes.
2.2 Hold and Wait:
OPERATING SYSTEMS 41
• Require processes to request all the resources they need at once before execution
begins, ensuring they don't hold any resources while waiting.
• Another approach is to require processes to release all held resources before
requesting new ones.
2.3 No Preemption:
• Allow the system to preempt resources from processes.
• If a process holding resources requests additional resources that cannot be
immediately allocated, preempt the process's current resources and allocate them to
others.
2.4 Circular Wait:
• Impose an ordering on resource acquisition to prevent circular wait.
• Require that each process requests resources in a predefined order, and release
resources before requesting those with a higher order.
3. Deadlock Avoidance
Deadlock avoidance requires the system to have additional information about how
resources are to be requested. The most commonly used algorithm for this is Banker’s
Algorithm:
3.1 Banker’s Algorithm:
• Designed for systems with multiple instances of each resource type.
• Each process must declare the maximum number of instances of each resource type it
may need.
• The system evaluates each resource allocation request to determine whether granting
it would leave the system in a safe state.
• A system is in a safe state if there exists a safe sequence of processes where each
process can finish executing with the available resources.
3.2 Safe State:
• A state is safe if the system can allocate resources to each process in some order and
still avoid a deadlock.
• If a system is in a safe state, there is no possibility of a deadlock.
OPERATING SYSTEMS 43
6. Examples of Deadlocks
• Resource Deadlocks: Multiple processes wait for resources held by others, leading to
a cycle.
o Example: Two processes, A and B, each holding a resource needed by the
other.
• Communication Deadlocks: Processes wait indefinitely for messages from each
other.
• Database Deadlocks: Transactions lock database rows in different orders, resulting in
a cycle of dependencies.
Memory Management in Operating Systems
Memory management is a crucial function of an operating system (OS) that manages
computer memory, including the allocation and deallocation of memory spaces to
processes. Efficient memory management ensures optimal system performance, stability,
and multitasking capabilities.
3. Virtual Memory
Virtual memory allows an OS to run applications that require more memory than is
physically available by using disk space to extend the apparent amount of available
memory.
3.1 Concepts:
OPERATING SYSTEMS 45
• Paging: Divides virtual memory into pages, which are loaded into frames in physical
memory as needed.
• Page Replacement Algorithms: Determine which pages to swap in and out of
physical memory.
o FIFO (First-In-First-Out): Replaces the oldest page in memory.
o LRU (Least Recently Used): Replaces the page that has not been used for the
longest period.
o Optimal Page Replacement: Replaces the page that will not be used for the
longest period in the future (requires future knowledge).
3.2 Benefits:
• Enables the execution of large applications that exceed physical memory capacity.
• Provides an abstraction of a large, contiguous memory space for applications.
• Reduces the need for physical memory, thus allowing multiple processes to run
simultaneously.
3.3 Swapping:
• Swapping is a technique where the OS swaps out entire processes from physical
memory to disk to free up space.
• When the swapped-out process is needed again, it is swapped back into physical
memory.
OPERATING SYSTEMS 46
5. Fragmentation
5.1 Internal Fragmentation:
• Occurs when fixed-size memory partitions are allocated to processes that are smaller
than the partition size.
• The unused memory within the partition is wasted.
5.2 External Fragmentation:
• Occurs when free memory is scattered in small blocks throughout the system.
• Can make it difficult to allocate large contiguous blocks to processes.
5.3 Compaction:
• A technique to reduce external fragmentation by relocating processes to consolidate
free memory into a single contiguous block.
• Time-consuming and resource-intensive.
OPERATING SYSTEMS 48
3. I/O Operations
3.1 Programmed I/O:
• The CPU is actively involved in I/O operations, polling the device to check if it is
ready for data transfer.
• Simple but inefficient as the CPU is busy-waiting, resulting in wasted CPU cycles.
3.2 Interrupt-Driven I/O:
• Devices generate interrupts to signal the CPU when they are ready for data transfer,
freeing the CPU to perform other tasks while waiting.
• More efficient than programmed I/O as it reduces CPU idle time.
• Requires an interrupt handler to manage and prioritize interrupts from multiple
devices.
3.3 Direct Memory Access (DMA):
• Allows devices to transfer data directly to and from memory without involving the
CPU for each byte of data.
• The CPU initializes the DMA controller, specifying the memory address and the
number of bytes to transfer.
• Once the transfer is complete, the DMA controller sends an interrupt to the CPU.
• Greatly improves efficiency, especially for large data transfers.
4. I/O Scheduling
I/O scheduling optimizes the order in which I/O requests are processed to enhance system
performance.
4.1 First-Come, First-Served (FCFS):
• Processes I/O requests in the order they arrive.
• Simple but can lead to suboptimal performance, especially with disk I/O where
requests are scattered across the disk.
4.2 Shortest Seek Time First (SSTF):
• Selects the I/O request that requires the least movement of the disk arm.
• Minimizes seek time, improving disk I/O efficiency.
• Can lead to starvation for requests far from the current disk head position.
4.3 SCAN and LOOK:
OPERATING SYSTEMS 49
• SCAN: The disk arm moves back and forth across the disk, servicing requests in one
direction until it reaches the end, then reversing direction.
• LOOK: Similar to SCAN but only goes as far as the last request in each direction
before reversing.
• Reduces the average seek time by distributing movement more evenly across the disk.
4.4 C-SCAN and C-LOOK:
• C-SCAN: The disk arm moves in one direction only, servicing requests, and jumps
back to the start once it reaches the end.
• C-LOOK: Similar to C-SCAN but only goes as far as the last request, then jumps
back to the start.
• Provides more uniform wait times compared to SCAN and LOOK.
6. Error Handling
• Detection: Identifying errors during I/O operations, such as disk read/write errors or
device malfunctions.
• Reporting: Notifying the OS or applications about errors to take corrective actions.
• Recovery: Techniques like retrying operations, using error-correcting codes (ECC), or
marking bad sectors on disks to handle errors.
OPERATING SYSTEMS 50
7. Device Independence and Naming
• Device Independence: Allows applications to perform I/O operations without
knowing the details of the hardware. The OS provides a uniform interface for
accessing devices.
• Uniform Naming: Devices are assigned logical names (e.g., /dev/sda1) that are used
to access them, abstracting away the hardware-specific details.
OPERATING SYSTEMS 51
2. File System Concepts
2.1 File:
• A logical unit of storage that contains data or programs.
• Has attributes such as name, type, size, creation date, and permissions.
2.2 File Structure:
• Unstructured: A simple stream of bytes (e.g., text files).
• Structured: Contains a predefined format or structure (e.g., databases).
2.3 File Types:
• Text Files: Contain readable characters (e.g., .txt).
• Binary Files: Contain binary data, typically not human-readable (e.g., executable
files).
• Directory Files: Contain references to other files, organizing them into a hierarchy.
• Special Files: Represent devices, sockets, or other resources.
2.4 File Attributes:
• Name: The identifier for the file.
• Type: The kind of file (e.g., text, binary).
• Location: The storage device and path where the file resides.
• Size: The size of the file in bytes.
• Protection: Permissions indicating who can read, write, or execute the file.
• Timestamps: Dates of creation, modification, and last access.
3. File Operations
The OS provides various file operations to manage files, including:
• Create: Creating a new file in the file system.
• Delete: Removing a file from the file system.
• Open: Accessing a file for reading or writing.
• Close: Terminating access to an open file.
• Read: Reading data from a file.
• Write: Writing data to a file.
• Append: Adding data to the end of a file.
OPERATING SYSTEMS 52
• Rename: Changing the name of a file.
• Seek: Moving the read/write pointer to a specific location in a file.
5. Directory Structure
Directories provide a way to organize files into a hierarchical structure, making it easier
to manage and locate files.
5.1 Single-Level Directory:
• All files are stored in a single directory.
• Simple but can lead to difficulties in file organization and name conflicts.
5.2 Two-Level Directory:
• Each user has their own directory, under which they can create and manage files.
• Reduces name conflicts and improves file organization.
5.3 Tree-Structured Directory:
• Directories are organized in a hierarchical tree structure, where each directory can
contain files and subdirectories.
• Offers flexibility and supports complex file organization.
5.4 Acyclic-Graph Directory:
• Allows directories to share subdirectories and files, creating an acyclic graph
structure.
• Facilitates sharing but requires mechanisms to handle multiple references to files and
directories.
OPERATING SYSTEMS 53
5.5 General Graph Directory:
• Supports arbitrary links between files and directories, creating a general graph
structure.
• Complex and may require cycle-detection algorithms to prevent circular references.
OPERATING SYSTEMS 54
9. File System Implementation
9.1 File Control Block (FCB):
• A data structure that contains information about a file, such as its name, location, size,
and access permissions.
• The OS maintains an FCB for each file in the system.
9.2 Free Space Management:
• Keeps track of unallocated disk space to efficiently allocate space for new files.
• Methods include bitmaps, linked lists, and free space tables.
9.3 Disk Scheduling:
• Algorithms like FCFS, SSTF, SCAN, and C-SCAN are used to optimize the order of
disk I/O operations, improving overall system performance.
OPERATING SYSTEMS 55