Chap 1
Chap 1
Run User Programs: It helps you run the applications you want to use.
Hardware: The physical parts of the computer, like the CPU, memory, and input/output devices.
Operating System: This manages and coordinates how the hardware is used by different applications and users.
Application Programs: These are the programs that perform specific tasks, like word processing or playing
games.
Users: This includes people, other machines, or even other computers that interact with the system.
Users want their computers to be easy to use and perform well, but they don’t usually care how resources (like
memory and processing power) are managed.
Shared Computers:
For shared systems (like mainframes), the operating system needs to make sure all users are happy and that
resources are used efficiently.
Dedicated Systems:
In dedicated systems (like workstations), resources are specifically assigned to one user, but they may still use
shared resources from servers.
Mobile Devices:
Smartphones and tablets have limited resources and are designed for usability and battery life. They often use
touch screens and voice recognition for user interaction.
Embedded Systems:
Some computers, like those in cars or appliances, operate with little or no user interface and run mostly on their
own.
Defining Operating Systems
Variety of Roles:
Operating systems come in many forms and are found in everything from toasters to spacecraft. They evolved
from military computers to general-purpose machines needing better resource management.
No Universal Definition:
There's no single definition for what an OS is. A good way to think of it is everything that comes with an OS
when you buy it.
Kernel vs. Other Software:
The kernel is the core part of the operating system that runs all the time. Other software that comes with the
OS is called system programs, and anything else (like games and office apps) is considered application programs.
Middleware:
Modern operating systems often include middleware, which helps application developers by providing
additional services like databases or graphics.
A computer system consists of one or more CPUs (the brains of the computer) and device controllers (which
manage peripherals like keyboards and printers). These connect through a common bus that allows them to
access shared memory.
Concurrent Execution:
The CPU and I/O devices (like hard drives and printers) can work at the same time, competing for access to
memory.
How It Works
Device Controllers:
Each type of device (like a printer or keyboard) has a device controller that manages it. Each controller has its
own local buffer (a small amount of memory to hold data temporarily).
Operating System Drivers:
Each device controller is managed by an operating system device driver, which is software that helps the OS
communicate with the hardware.
Data Movement:
The CPU transfers data between the main memory (where all data is stored) and the local buffers of the device
controllers.
Input/Output (I/O) operations occur between the device and its local buffer.
Interrupts:
When a device controller completes its task, it sends a signal (called an interrupt) to the CPU to inform it that
it’s done. This allows the CPU to know when it can process the data from that device.
In short, computer systems are organized to allow the CPU and devices to work together efficiently, using local
buffers and device drivers to manage data transfer and operations.
When an interrupt occurs, control is passed to a special piece of code called the interrupt service routine (ISR).
The interrupt vector is a list that contains the addresses of all these routines.
Saving State:
The system must save the location (address) of the instruction that was interrupted. This ensures that the CPU
can return to this point after handling the interrupt.
Traps/Exceptions:
A trap (or exception) is a type of interrupt generated by software. It can happen due to an error (like dividing by
zero) or a request from the user (like pressing a key).
Interrupt-Driven OS:
The operating system relies on interrupts to respond to events and manage tasks efficiently.
Interrupt Handling
State Preservation:
When an interrupt occurs, the operating system saves the current state of the CPU, including the registers
(small storage locations) and the program counter (which points to the next instruction to execute).
Identifying the Interrupt:
In this method, once an I/O operation starts, the program waits until it finishes before continuing. This
means:The CPU is idle and does nothing while waiting (using a "wait instruction").
This can lead to inefficiency since the CPU can't process other tasks.
Only one I/O request can be active at a time, so no simultaneous I/O operations can occur.
Not Waiting for I/O Completion:
Here, after starting an I/O operation, the program continues running without waiting. This involves:Making a
system call to the operating system, which allows the program to request I/O without stalling.
The operating system maintains a device-status table that keeps track of each I/O device, including its type,
address, and current state.
The OS can check the status of devices and update the table when interrupts occur (when a device signals that
it has finished).
Summary
The choice between these methods affects how efficiently a computer can handle tasks. Waiting for I/O can
waste CPU time, while allowing the CPU to keep working while waiting for I/O can improve performance by
handling multiple operations more effectively.
Storage Structure
1. Main Memory
Definition: This is the primary storage that the CPU can access directly.
Characteristics:Random Access: You can read or write data in any order.
Volatile: It loses its data when the power is turned off.
Type: Usually made of Dynamic Random-Access Memory (DRAM).
2. Secondary Storage
Definition: This is additional storage that provides larger, permanent storage space.
Characteristics:Non-volatile: It retains data even when the power is off.
Types of Secondary Storage
Hard Disk Drives (HDD):
Summary
In summary, computer storage is organized into main memory for quick access and secondary storage for larger,
long-term data retention, with various technologies providing different benefits in speed and capacity.
Storage Hierarchy
Organization: Storage systems are arranged in a hierarchy based on three main factors:
This is the process of copying frequently used data into a faster storage area. For example, main memory (RAM)
acts as a cache for data stored on slower secondary storage (like hard drives).
Device Drivers:
Each device controller (like a printer or hard drive) has a device driver that manages I/O operations.
The driver provides a consistent way for the operating system (kernel) to communicate with different
hardware.
Definition: DMA is a method used for high-speed I/O devices that can move data quickly, nearly at the speed of
memory.
Function:The device controller can transfer large blocks of data directly to main memory without needing the
CPU to get involved.
This reduces the number of interrupts generated—only one interrupt is created for each block of data instead
of one for each byte, making the process more efficient.
Summary
In summary, the storage hierarchy helps manage data efficiently by balancing speed, cost, and volatility, while
caching and direct memory access enhance performance and reduce CPU workload during I/O operations.
Operating-System Operations
Bootstrapping
Bootstrap Program: This is a small program that starts the computer. Its main job is to initialize the system and
load the kernel (the core part of the operating system).
Kernel Loading: Once the bootstrap program runs, it loads the kernel into memory.
Starting Daemons: After loading the kernel, it starts system daemons (background services) that provide
various functions outside the kernel.
Kernel Interrupts
The kernel operates by responding to interrupts:Hardware Interrupts: Triggered by devices (like a keyboard or
mouse) to signal the CPU.
Occur when a program requests a service from the operating system (known as a system call).
Can arise from issues like infinite loops or processes trying to interfere with each other.
If a job has to wait (e.g., for I/O), the OS switches to another job, maximizing CPU usage.
Multitasking (Timesharing)
Extension of Multiprogramming: In multitasking, the CPU switches between jobs frequently enough that users
can interact with each job while it’s running, leading to a more interactive experience.
Key Features:Response Time: The system aims for a response time of less than one second.
Each user can run at least one program (called a process) in memory.
If multiple jobs are ready to run, CPU scheduling determines which one runs next.
Swapping: If there isn't enough memory for all processes, some are moved in and out of memory.
Virtual Memory: This allows processes to run even if they aren't fully loaded in memory.
Summary
In summary, operating systems manage how computers start up, handle multiple jobs efficiently, and provide
interactive experiences for users through sophisticated scheduling and memory management techniques.
Purpose: In a multiprogrammed system, memory is organized to allow multiple programs (processes) to run
simultaneously.
Structure: Each process is allocated space in memory, which typically includes:Text Segment: Contains the
program code.
User Mode: When a user program is running, the mode bit is set to “user.” This restricts access to certain system
resources and instructions.
Kernel Mode: When the operating system is executing, the mode bit is set to “kernel.” This allows full access to
all system resources.
Mode Bit:
User programs cannot change the mode bit directly; it can only be altered through system calls.
Privileged Instructions: Some instructions can only be executed in kernel mode to maintain system security and
stability.
When a user program needs to request a service from the operating system (like reading a file), it makes a
system call. This changes the mode to kernel mode.
Timer
Purpose: To prevent a single process from running indefinitely (infinite loops) or hogging system resources.
Functionality:A timer is set to generate an interrupt after a specified time period.
The operating system sets this timer (using a privileged instruction).
A counter counts down using the physical clock.
When the counter reaches zero, it triggers an interrupt, allowing the OS to regain control, schedule other
processes, or terminate the program if it exceeds its time limit.
Summary
In summary, the memory layout in a multiprogrammed system supports efficient execution of multiple
processes. Dual-mode operation ensures system protection by distinguishing between user and kernel modes,
while timers help manage process execution to prevent resource monopolization.
Process Management
Definition of a Process:
A process is a program that is currently being executed. It is an active entity that requires resources to perform
its tasks, such as:CPU: For processing.
Memory: To hold instructions and data.
I/O devices: For input and output operations.
Files: For data storage.
Process Termination:
When a process finishes, the operating system must reclaim any resources (like memory or files) that were
used.
Types of Processes:
Single-threaded Process: Has one program counter, executing instructions one after another until it completes.
Multi-threaded Process: Has multiple threads, each with its own program counter, allowing multiple sequences
of instructions to run concurrently.
Concurrency:
Many processes can run at the same time, either by sharing a single CPU (multiplexing) or by using multiple
CPUs.
Process Management Activities
The operating system handles several key activities related to processes:
Creating and Deleting Processes: Manage the lifecycle of both user and system processes.
Suspending and Resuming Processes: Temporarily stop and restart processes as needed.
Process Synchronization: Ensure that processes operate smoothly when they need to share resources.
Process Communication: Allow processes to exchange information.
Deadlock Handling: Manage situations where processes are stuck waiting for each other.
Memory Management
Execution Requirements:
The operating system provides a consistent way to interact with different types of storage through the concept
of a file, which abstracts physical storage details.
File and Device Management:
Each storage medium (like hard drives or tape drives) has unique properties, such as access speed and data
transfer rates.
File-System Management Activities
File Organization:
Creating and Deleting Files and Directories: Manage the storage structure.
Manipulating Files and Directories: Provide tools for users to interact with the file system.
Mapping Files to Storage: Determine how files are physically stored on the disk.
Backup Management: Ensure files are backed up to stable, non-volatile storage.
Summary
In summary, operating systems manage processes, memory, and files to ensure efficient execution of programs,
optimal use of resources, and organized data storage. Each of these areas involves specific activities that help
maintain system performance and user accessibility.
Mass-Storage Management
Purpose of Mass Storage:
Disks (like hard drives and SSDs) are used to store data that either doesn't fit in main memory or needs to be
kept for a long time.
Importance of Management:
Proper management of mass storage is crucial because the overall speed of computer operations depends
heavily on how efficiently the disk subsystem functions.
Key OS Activities in Mass Storage Management
Mounting and Unmounting:
Keeping track of available space on storage devices to know where new data can be saved.
Storage Allocation:
Determining the order in which disk operations are performed to optimize performance.
Partitioning:
Dividing the disk into sections that can be managed separately (e.g., different file systems or operating
systems).
Protection:
Ensuring data is secure and that only authorized users can access it.
Caching
Definition:
Caching is a technique used to temporarily store frequently accessed data in a faster storage area, called a
cache.
How Caching Works:
When data is needed, the system first checks the cache:If the data is in the cache: It’s used directly from there,
which is quick.
If the data is not in the cache: It’s retrieved from slower storage, then copied to the cache for future use.
Cache Characteristics:
The cache is typically smaller than the main storage it’s caching data from.
Effective cache management is critical, involving decisions about cache size and what to replace when new data
needs to be added.
When data, like “A,” moves from a slower storage medium (like a disk) to a faster one (like a register), it’s
important to ensure that the most recent version of the data is used.
Multitasking Environments:
In systems where multiple tasks run simultaneously, it’s crucial to access the latest value of data, regardless of
where it’s stored in the hierarchy.
Multiprocessor Environments:
In systems with multiple CPUs, cache coherency must be maintained. This means ensuring all CPUs have the
most up-to-date version of the data stored in their caches.
Distributed Environments:
These environments can be more complex since multiple copies of the same data might exist across different
locations. Various strategies are needed to manage these copies effectively.
I/O Subsystem
Purpose of the I/O Subsystem:One of the operating system's roles is to abstract the complexities of hardware
devices from users, making it easier to interact with different types of hardware.
Key Responsibilities of the I/O Subsystem
Memory Management for I/O:
This includes:Buffering: Temporarily storing data during transfer to manage speed differences between
devices.
Caching: Storing frequently accessed data in faster storage to improve performance.
Spooling: Overlapping the output of one job with the input of another job to optimize resource use.
Device Driver Interface:
Provides a general interface for communicating with I/O devices, ensuring that applications can interact with
various hardware uniformly.
Drivers for Specific Hardware:
Each type of hardware device (like printers, disks, or network cards) requires a specific driver to translate
generic OS commands into device-specific actions.
Summary
In summary, managing the movement of data across different storage levels and ensuring efficient I/O
operations are crucial roles of an operating system. These functions help maintain system performance and
reliability in various computing environments.
Each user has a unique identity (user ID) that includes a name and a corresponding number. This helps the OS
determine who can access what resources.
File and Process Association:
The user ID is linked to all files and processes belonging to that user, allowing the OS to manage access controls
effectively.
Group Identification:
Users can be organized into groups (group ID), which simplifies management by allowing permissions to be set
for a group rather than individually.
Privilege Escalation:
This allows a user to temporarily gain higher privileges to perform certain actions that they wouldn’t normally
have permission for.
Virtualization
Definition:Virtualization enables operating systems to run applications within other operating systems. This is
becoming increasingly important in IT environments.
Types of Virtualization:
Emulation:
Used when the source CPU type differs from the target (e.g., running applications compiled for PowerPC on an
Intel x86). This method is typically slower because it translates instructions on the fly.
Interpretation:
A method where the system interprets code at runtime, which can also slow down performance.
Virtualization with Native Compilation:
In this scenario, both the host and guest operating systems are compiled for the same CPU type. For example,
using VMware to run Windows XP guests on a native Windows XP host. This is generally faster than emulation.
Virtual Machine Manager (VMM):
Also known as a hypervisor, this software manages virtual machines, providing the virtualization service and
enabling multiple OS instances to run concurrently on a single physical machine.
Summary
In summary, protection and security are essential for managing user access and safeguarding against attacks in
an operating system. Virtualization enhances flexibility and resource utilization by allowing multiple operating
systems to run simultaneously, supporting various applications and environments.
Users can run different OSes on the same machine for various purposes, such as:Compatibility Testing: For
example, an Apple laptop can run macOS as the host and Windows as a guest OS, allowing users to use
applications from both environments.
Development: Developers can create and test applications for multiple operating systems without needing
multiple physical machines.
Quality Assurance: Testers can verify applications across different environments easily.
Data Center Management: Virtualization allows efficient management of compute resources in data centers,
enabling better resource allocation and flexibility.
Native Virtual Machine Managers (VMM):
Some virtualization platforms can run directly on hardware without a general-purpose host OS. Examples
include:VMware ESX
Citrix XenServer
These VMMs act as both the virtualization layer and the host, optimizing performance and resource
management.
Distributed Systems
Definition:
A distributed system consists of multiple independent systems (which may use different hardware and
software) connected via a network.
Networking Basics:
Communication between these systems typically uses protocols like TCP/IP. Common types of networks
include:Local Area Network (LAN): Covers a small geographic area, like a home or office.
Wide Area Network (WAN): Covers larger geographic areas, such as cities or countries.
Metropolitan Area Network (MAN): Spans a city or a large campus.
Personal Area Network (PAN): Connects personal devices, usually within a very short range (e.g., Bluetooth).
Network Operating System (NOS):
This system provides the necessary features for different computers in a network to communicate and share
resources effectively. Key functions include:Message Exchange: Facilitates communication between systems.
Single System Illusion: It makes the networked systems appear as a single cohesive system to the user,
enhancing usability and accessibility.
Summary
In summary, virtualization is a powerful tool for maximizing resource use and flexibility across various
applications and testing environments. Distributed systems leverage networking to connect multiple
independent systems, allowing them to function collaboratively as if they were a single unit, enhancing
communication and resource sharing.
Also known as parallel systems or tightly-coupled systems, these have multiple processors working together.
Advantages:
Asymmetric Multiprocessing (AMP):Each processor is assigned a specific task, with some processors handling
more critical operations.
Symmetric Multiprocessing (SMP):All processors share the same tasks and resources, allowing them to work
more interchangeably.
Dual-Core Design
Multi-Chip and Multi-Core Systems:Modern computers often feature multiple processors on a single chip
(dual-core or multi-core designs) or multiple separate chips, allowing for enhanced multitasking and
performance.
Non-Uniform Memory Access (NUMA) System
Definition:In a NUMA system, processors have different access times to different memory locations. This
architecture is designed to optimize performance by minimizing memory access delays.
Clustered Systems
Definition:
Clustered systems consist of multiple separate computers (nodes) working together, often connected via a
Storage Area Network (SAN).
High-Availability Services:
These systems are designed to remain operational even if one or more nodes fail.
Types of Clustering:Asymmetric Clustering: One machine is kept in a standby mode to take over if the main
machine fails.
Symmetric Clustering: Multiple nodes run applications simultaneously and monitor each other for failures.
High-Performance Computing (HPC):
Some clusters are optimized for HPC, requiring applications to be specifically written to take advantage of
parallel processing.
Distributed Lock Manager (DLM):
Some clustered systems use DLMs to manage access to shared resources and prevent conflicting operations
among nodes.
Summary
In summary, computer system architecture can vary significantly, with single processors, multiprocessor setups,
and clustered systems each offering different benefits. Multiprocessor systems enhance performance and
reliability, while clustered systems provide high availability and the ability to perform high-performance
computing tasks.
Clustered Systems
Definition:
Clustered systems consist of multiple interconnected computers (or nodes) that work together to provide high
availability and reliability.
Key Features:
High Availability: The system continues to function even if one or more nodes fail.
Load Balancing: Distributes workloads across multiple nodes for better performance.
Scalability: Additional nodes can be added easily to improve capacity.
Computing Environments
Different computing environments support various use cases and architectures:
Traditional:
Devices like smartphones and tablets that rely on wireless networks for connectivity.
Designed for portability and often use apps tailored for mobile use.
Client-Server:
A model where multiple client devices request resources or services from a central server.
Common in business settings for data storage and application hosting.
Peer-to-Peer (P2P):
A decentralized network where each participant (or peer) can act as both a client and a server.
Often used for file sharing and collaboration without a central authority.
Cloud Computing:
Services and resources are provided over the Internet, allowing users to access data and applications remotely.
Offers scalability, flexibility, and on-demand resource allocation.
Real-time Embedded:
Mobile Computing
Devices: Includes smartphones, tablets, and other handheld devices.
Functional Differences from Laptops:Extra Features: Mobile devices often come with advanced sensors like
GPS and gyroscopes.
New App Types: These features enable innovative applications, such as augmented reality.
Connectivity: Use wireless technologies (like Wi-Fi) and cellular networks for internet access.
Leading Operating Systems: Apple iOS and Google Android.
Client-Server Computing
Structure:In this model, "smart" PCs act as clients that request services from more powerful "servers."
Types of Servers:Compute-Server System: Provides services like database access.
File-Server System: Allows clients to store and retrieve files.
Transition: Replaced "dumb" terminals (basic input/output devices) with capable PCs.
Peer-to-Peer (P2P) Systems
Model: All nodes in the network are considered equal; there is no distinct client-server hierarchy.
Node Roles: Each node can act as a client, server, or both.
Joining the Network:Nodes can register their services with a central directory or broadcast their presence to
find services.
Examples: Applications like Napster, Gnutella, and VoIP services like Skype.
Cloud Computing
Definition: Offers computing resources, storage, and applications over the internet as a service.
Virtualization Foundation: Cloud services often rely on virtualization technology to manage resources
efficiently.
Examples: Services like Amazon EC2 provide extensive computing power and storage, with users paying only
for what they use.
Summary
These computing paradigms illustrate how technology adapts to different needs, from mobile devices that
leverage unique features to the flexibility and scalability offered by cloud computing. Each model has distinct
characteristics, making it suitable for various applications and user experiences.
Public Cloud: Accessible to anyone over the internet; services are offered on a pay-per-use basis.
Private Cloud: Exclusively used by a single organization, managed internally or by a third party.
Hybrid Cloud: Combines both public and private cloud resources, allowing for flexibility and scalability.
Service Models:
Software as a Service (SaaS): Applications available via the internet (e.g., Google Docs).
Platform as a Service (PaaS): Provides a ready-to-use software stack for developers (e.g., Google App Engine).
Infrastructure as a Service (IaaS): Offers fundamental computing resources, like virtual machines and storage
(e.g., Amazon S3).
Cloud Environment Components:
Comprises traditional operating systems, virtual machine managers (VMMs), and cloud management tools.
Security Measures: Essential for protecting data and applications, often involving firewalls and encryption.
Load Balancers: Distribute incoming traffic across multiple servers to optimize resource use and improve
response times.
Real-Time Embedded Systems
Characteristics:Widely used in applications requiring immediate processing (e.g., medical devices, automotive
systems).
Utilize specialized real-time operating systems (RTOS) with strict time constraints.
Correct functionality depends on meeting these time constraints.
Free and Open-Source Operating Systems
Definition: These operating systems are available in source code format, allowing anyone to study, modify, and
distribute them.
Philosophy: Counteracts restrictive practices like Digital Rights Management (DRM).
Key Organizations:Free Software Foundation (FSF): Promotes free software through the GNU General Public
License (GPL).
Examples:GNU/Linux, BSD UNIX (which influences macOS), and others.
Virtualization Tools:Tools like VMware Player and VirtualBox enable users to run multiple operating systems on
one machine, facilitating exploration and experimentation.
The Study of Operating Systems
Current Landscape:
The rise of open-source has made studying operating systems more accessible.
Students can analyze operating systems by examining the source code rather than relying solely on
documentation.
Virtualization Impact:
Virtualization tools allow students to experiment with various operating systems without the need for
additional hardware.
Open-source projects enable students to transition from learning to actively contributing or developing their
own operating systems.
Opportunities for Development:
With access to source code, motivated students can create new operating system distributions, fostering
innovation and learning in computer science.
Summary
The evolution of cloud computing, real-time systems, and open-source operating systems presents numerous
opportunities for learning and innovation. The increasing accessibility of resources allows students and
developers to explore, experiment, and contribute to the field of operating systems in ways that were
previously difficult or impossible.
1. Linked Lists
Singly Linked List: Each node points to the next, allowing for efficient insertions and deletions.
Doubly Linked List: Nodes have pointers to both the next and previous nodes, facilitating traversal in both
directions.
Circular Linked List: The last node points back to the first, making it possible to traverse the list indefinitely.
2. Binary Search Trees
A tree structure where each node has at most two children; left child values are less than the parent, and right
child values are greater.
Performance:Unbalanced BST: Search time can be O(n).
Balanced BST (e.g., AVL tree): Ensures O(log n) search time.
3. Hash Maps
Utilizes a hash function to map keys to values, allowing for average-case constant time complexity for search,
insert, and delete operations.
4. Bitmaps
A compact array representation where each bit represents the status (used/unused) of a resource, enabling
quick status checks.
5. Linux Kernel Data Structures
Defined in specific header files such as:<linux/list.h> for linked lists.
<linux/kfifo.h> for FIFO queues.
<linux/rbtree.h> for red-black trees.
These data structures form the backbone of kernel operations, allowing efficient resource management and
process scheduling.