Operating System Study Material Guide
Operating System Study Material Guide
UNIT 1 NOTES
A Real-Time Operating System (RTOS) is an operating system designed to handle tasks with strict
timing constraints, where the correctness depends not only on the logical result but also on when that
result is delivered.
Key Characteristics
1. Deterministic timing - RTOSes provide predictable response times, ensuring tasks complete within
specified deadlines. This differs from general-purpose operating systems that optimize for overall
throughput rather than timing guarantees.
2. Priority-based scheduling - Tasks are assigned priorities, and the scheduler ensures higher-priority
tasks preempt lower-priority ones immediately when needed. Common algorithms include Rate
Monotonic Scheduling (RMS) and Earliest Deadline First (EDF).
3. Minimal interrupt latency - The time between an interrupt occurring and the system responding is
kept as low and predictable as possible, often in microseconds.
Types of Real-Time Systems
Hard real-time - Missing a deadline is catastrophic and could cause system failure. Examples include
airbag controllers, pacemakers, and nuclear reactor controls.
Soft real-time - Missing occasional deadlines is undesirable but not catastrophic. Examples include
video streaming, audio processing, and telecommunications.
Firm real-time - Missing deadlines makes the result useless, but doesn't cause system failure.
Examples include live video conferencing where late frames are discarded.
Common RTOS Examples
Commercial: VxWorks, QNX, ThreadX, INTEGRITY, RTX Open source: FreeRTOS, RT-Linux,
RTEMS, Zephyr Academic/Research: MINIX (real-time variant), L4 microkernel family
Applications
RTOSes are essential in embedded systems, industrial automation, automotive electronics, medical
devices, aerospace systems, robotics, and telecommunications equipment where timing predictability
is critical for safety or performance.
The main trade-off is that RTOSes often sacrifice overall system throughput and feature richness to
achieve timing predictability, making them specialized tools for specific applications rather than
general-purpose computing platforms.
A Multiprocessor Operating System is designed to manage and coordinate multiple processors (CPUs)
within a single computer system, enabling parallel execution of tasks and efficient resource sharing
across processors.
System Architectures
Symmetric Multiprocessing (SMP) - All processors are identical and share the same memory and I/O
resources. Each processor can execute any task, including operating system functions. This is the most
common architecture in modern multi-core systems.
Asymmetric Multiprocessing (AMP) - Processors have different roles, with one master processor
handling OS functions and scheduling while slave processors execute assigned tasks. Less common in
modern systems but still used in specialized applications.
Non-Uniform Memory Access (NUMA) - Processors have faster access to local memory than remote
memory, requiring the OS to consider memory locality when scheduling tasks and allocating
resources.
Process Synchronization - Multiple processors accessing shared resources simultaneously can cause
race conditions. The OS provides synchronization primitives like mutexes, semaphores, and atomic
operations to coordinate access.
Load Balancing - The OS must distribute tasks evenly across processors to prevent some from being
idle while others are overloaded. This involves sophisticated scheduling algorithms that consider
processor affinity and workload characteristics.
Cache Coherency - When multiple processors cache the same data, the OS must ensure consistency.
Hardware cache coherency protocols (like MESI) work with OS memory management to maintain
data integrity.
Deadlock Prevention - With multiple processors competing for resources, the OS must implement
strategies to detect, prevent, or resolve deadlocks through careful resource ordering and timeout
mechanisms.
A Multitasking Operating System allows multiple tasks or processes to run concurrently on a single
processor or multiple processors, creating the illusion that all tasks are executing simultaneously even when
they're actually sharing CPU time.
Types of Multitasking
Preemptive Multitasking - The operating system controls task switching and can interrupt a running
task at any time to give CPU time to another task. This prevents any single task from monopolizing
the processor. Modern operating systems like Windows, Linux, and macOS use this approach.
Cooperative Multitasking - Tasks voluntarily yield control to other tasks. A misbehaving task can
hang the entire system by not yielding control. Early versions of Windows (3.1) and classic Mac OS
used this model.
Time-Sharing - CPU time is divided into small time slices (typically milliseconds), and each task gets
a turn to execute. When a time slice expires, the OS switches to the next task in the queue.
Key Components
Process Scheduler - Determines which task runs next based on scheduling algorithms like Round
Robin, Priority-based, Shortest Job First, or Multilevel Queue scheduling. The scheduler must balance
fairness, responsiveness, and system throughput.
Context Switching - The mechanism for saving the current state of one task (registers, program
counter, stack pointer) and loading the state of another task. This overhead must be minimized for
efficient multitasking.
Memory Management - Each task needs its own memory space, protected from other tasks. Virtual
memory systems provide isolation and allow tasks to have larger address spaces than physical
memory.
Inter-Process Communication (IPC) - Tasks often need to communicate and share data. The OS
provides mechanisms like pipes, message queues, shared memory, and semaphores for safe
communication.
Advantages
Improved CPU Utilization - While one task waits for I/O operations, other tasks can use the CPU,
dramatically improving overall system efficiency.
Enhanced User Experience - Users can run multiple applications simultaneously, such as browsing the
web while playing music and editing documents.
Better Resource Sharing - Multiple tasks can share system resources like printers, network
connections, and storage devices through OS-mediated access.
Fault Isolation - If one task crashes, other tasks can continue running unaffected (in properly designed
systems with memory protection).
Time sharing operating systems are designed to allow multiple users to access a computer system
simultaneously by rapidly switching the CPU between different user processes. Here's how they work
and their key characteristics:
Core Principles
Multitasking and Multiprogramming - The OS keeps multiple programs in memory simultaneously and
switches between them so quickly that users experience seemingly concurrent execution. Each process
gets small time slices (typically 10-100 milliseconds) before the CPU switches to the next process.
Interactive Response - Unlike batch processing systems, time sharing OS provides immediate feedback
to users through terminals or workstations, making the computer feel responsive even when serving
many users.
Key Components
Scheduler - The heart of the system that determines which process runs next. Common scheduling
algorithms include round-robin (each process gets equal time slices), priority-based scheduling, and
multilevel feedback queues that adjust priorities based on process behavior.
Memory Management - Since multiple programs must coexist in memory, the OS uses techniques like
virtual memory, paging, and segmentation to efficiently allocate and protect memory spaces for different
users.
Process Management - The OS maintains process control blocks for each running program, tracking
their state, register contents, and memory allocation so it can seamlessly switch between them.
Multiprogramming operating systems allow multiple programs to reside in memory simultaneously and
share the CPU, but differ from time sharing systems in their approach and goals. Here's a comprehensive
overview:
Core Concept
Memory Utilization - The primary goal is to keep the CPU busy by having multiple programs loaded in
memory at once. When one program performs I/O operations or waits for resources, the CPU can switch
to executing another program instead of sitting idle.
Non-interactive Processing - Unlike time sharing systems that focus on user interaction,
multiprogramming systems traditionally emphasize throughput and efficient resource utilization, often
processing batch jobs without direct user intervention.
How It Works
Job Scheduling - The OS maintains a job queue of programs waiting to execute. When the system starts,
it loads several programs into different areas of memory simultaneously.
CPU Switching - When the currently executing program encounters an I/O operation, system call, or
other blocking event, the OS immediately switches the CPU to another ready program. This eliminates
the idle time that would occur in single-program systems.
Memory Partitioning - Memory is divided into fixed or variable partitions to hold multiple programs.
Each partition is protected from others to prevent interference.
In a Multiprogramming OS, multiple programs are loaded into memory at the same time. The
CPU switches from one job to another to improve CPU utilization. When one program waits for I/O,
another is given the CPU.
Key Features:
Better CPU usage
No direct user interaction
Mostly used in batch systems
Examples:
Early IBM Mainframes
Batch operating systems were among the earliest computer operating systems, designed to process jobs
sequentially without user interaction during execution. They emerged in the 1950s and 1960s to improve
the efficiency of early mainframe computers.
Core Characteristics
Sequential Job Processing - Jobs are collected together into batches and processed one after another in a
predetermined sequence. Once a batch begins execution, it runs to completion without interruption or user
intervention.
Non-interactive Operation - Users cannot interact with their programs while they're running. Instead, they
submit jobs with all necessary instructions, data, and parameters, then wait for the complete results.
Operator-mediated Execution - Computer operators collect jobs from users, organize them into batches,
load them onto the system, and distribute results back to users after processing completes.
Job Submission - Users prepare their programs and data on punch cards, magnetic tape, or other input
media, along with job control language (JCL) instructions that specify resource requirements and
processing parameters.
Batch Formation - Operators group similar jobs together to maximize efficiency. For example, all
FORTRAN compilation jobs might be batched together, followed by all COBOL jobs.
Automatic Job Sequencing - The OS automatically loads and executes each job in the batch sequence.
When one job finishes, the system immediately begins the next job without manual intervention.
Resource Management - The system allocates memory, I/O devices, and other resources to each job as
needed, then releases them when the job completes.
Advantages
High Throughput - By eliminating setup time between jobs and running similar jobs consecutively, batch
systems achieve high overall system utilization and job throughput.
Cost Effectiveness - Expensive mainframe time is used efficiently since the CPU rarely sits idle between
jobs, making computing more economical for organizations.
DOS:
o mkdir folder: Create folder
o dir: List files
o cls: Clear screen
UNIX:
o $ mkdir OSY: Create folder
o $ cd OSY, $ cat>file: Create file
o $ ls: List files
o $ clear: Clear screen
Common examples:
2. File Management
What it does: Handles file operations like creating, reading, writing, and deleting files.
Common examples:
3. Device Management
What it does: Controls hardware devices like printers, keyboards, and storage devices.
Common examples:
4. Information Maintenance
Common examples:
What it does: Allows different programs to talk to each other and share data.
Common examples:
Key Point: System calls are like a bridge between user programs and the operating system - they
let programs ask the OS to do things they can't do themselves, like accessing hardware or
managing files.
6 Marks Questions
1. List and explain Six Services of OS.
1. User Interface
The User Interface (UI) is the part of the OS that allows interaction between the user and the
computer hardware.
Types:
Command Line Interface (CLI): Users type text commands (e.g., DOS, UNIX).
Graphical User Interface (GUI): Users interact via windows, icons, menus, and pointers
(e.g., Windows, macOS, Android).
Purpose:
Provides an accessible way for users to operate the system.
Allows execution of programs, file management, system configuration, etc.
Functions:
Loads programs from storage into memory.
Allocates CPU and resources.
Manages execution, including starting and stopping.
Handles multitasking and context switching.
Example:
When you open MS Word or a browser, the OS loads the application into memory and schedules it for
execution.
3. I/O Operations
The OS manages input/output operations between the CPU, memory, and external devices such as
keyboard, mouse, disk, printer, etc.
Functions:
Provides standardized I/O interfaces so user programs don't access hardware directly.
Handles buffering, caching, and spooling.
Manages device drivers for communication with hardware.
Example:
Reading a file from disk or printing a document goes through the I/O management layer of the OS.
5. Communication
OS supports inter-process communication (IPC) to allow data exchange between processes.
Methods:
Message Passing: Data is exchanged in messages (e.g., pipes, sockets).
6. Error Detection
The OS continuously monitors the system for potential errors and takes corrective actions to ensure
stability and reliability.
Functions:
Detects hardware failures, illegal memory access, and software bugs.
Logs errors and alerts the user or administrator.
May attempt automatic recovery or shut down affected programs.
Example:
If a program crashes or a USB device malfunctions, the OS detects and handles the error gracefully.
2. Task Scheduler
The Task Scheduler is an essential component of the OS that determines which process should run at
any given time.
Functions:
CPU Scheduling: Allocates CPU time to processes based on algorithms like FCFS, Round
Robin, Priority.
Multitasking Support: Helps in running multiple processes efficiently.
Priority Management: Gives preference to high-priority tasks or real-time processes.
Automation: Can run specific tasks at scheduled times (e.g., backup, virus scans).
Example:
In Windows, the Task Scheduler utility lets users schedule tasks like running antivirus scans at night
automatically.
3. Performance Monitor
The Performance Monitor tool keeps track of the overall system performance including CPU,
memory, disk, and network usage.
Functions:
Real-time Monitoring: Displays live usage statistics of system resources.
Logging and Alerts: Keeps logs of usage history and alerts if resource usage exceeds limits.
Helps in Troubleshooting: Identifies which processes or hardware are causing system
slowdowns.
4. System Security
System Security tools ensure that the system is protected from unauthorized access, data breaches,
and malware.
Functions:
User Authentication: Verifies the identity of users via passwords, biometrics, etc.
Access Control: Grants or denies access to system files, programs, and devices.
Encryption: Secures sensitive data from being accessed or modified.
Firewall and Antivirus: Blocks suspicious activities and scans for malware.
Example:
Windows Defender, Linux user/group permission system (chmod, chown), and firewalls are part of
OS security.
5. User Management
The User Management tool is used to create, modify, and manage user accounts and their access
rights.
Functions:
User Account Creation/Deletion: Admins can add or remove users.
Group Management: Users can be grouped for easier permission assignment.
Role Assignment: Defines what operations each user can perform.
Login Tracking: Keeps record of login attempts, session duration, etc.
Example:
In Linux, commands like adduser, usermod, passwd handle user management; in Windows, the "User
Accounts" panel or net user command does similar tasks.
1. Process Management:
A program is a set of instructions. When CPU is allocated to a program, it can start its execution. A
program in execution is a process. A word processing program run by a user on a PC is a process.
A process needs various system resources including CPU time, memory, files and I/O devices to
complete the job execution. These resources can be given to the process when it is created or
allocated to it while it is running. The operating system responsible for the following activities in
connection with process management:
• Creation and deletion of user and system processes.
• Suspension and resumption of processes.
• A mechanism for process synchronization.
• A mechanism for process communication.
• A mechanism for deadlock handling.
2. Main-Memory Management
Main memory is a large array of words or bytes, ranging in size from hundreds of thousands to
billions. Each word or byte has its own address. Main memory is a repository of quickly accessible
data shared by the CPU and I/O devices. The central processor reads instructions from main
memory during the instruction fetch cycle and both reads and writes data from main memory
during the data fetch cycle. The main memory is generally the only large storage device that the
CPU is able to address and access directly. The operating system responsible for the following
activities in connection with main memory s management:
• Keeping track of which parts of memory are currently being used and by whom.
• Deciding which processes (or parts thereof) and data to move into and out of memory.
• Allocating and deallocating memory space as needed.
3. File Management
A file is a collected of related information defined by its creator. Computers can store files on the disk
(secondary storage), which provide long term storage. Some examples of storage media are magnetic
tape, magnetic disk and optical disk. Each of these media has its own properties like speed, capacity,
and data transfer rate and access methods. A file system normally organized into directories to ease
their use. These directories may contain files and other directions.
The operating system responsible for the following activities in connection with file management:
• The creation and deletion of files.
• The creation and deletion of directions.
• The support of primitives for manipulating files and directions.
• The mapping of files onto secondary storage.
• The backup of files on stable storage media.
Input / Output device management provides an environment for the better interaction between system
and the I/O devices (such as printers, scanners, tape drives etc.). To interact with I/O devices in an
effective manner, the operating system uses some special programs known as device driver. The
device drivers take the data that operating system has defined as a file and then translate them into
streams of bits or a series of laser pulses (in regard with laser printer). The I/O subsystem consists of
several components:
5. Secondary-Storage Management
The computer system provides secondary storage to back up main memory. Secondary storage is
required because main memory is too small to accommodate all data and programs, and the data that
it holds is lost when power is lost. Most of the programs including compilers, assemblers, word
processors, editors, and formatters are stored on a disk until loaded into memory. Secondary storage
consists of tapes drives, disk drives, and other media. The operating system is responsible for the
following activities in connection with disk management:
• Free space management
• Storage allocation
• Disk scheduling.
2 Marks Questions
1. Define Process, PCB.
Process:- A process is a program in execution. Process is also called as job, task or unit of
work.
PCB:- Process Control Block is a data structure that contains information of the process
related to it. The process control block is also known as a task control block, entry of the
process table, etc
3. Thread vs Multithreading
4 Marks Questions
1. Draw process state diagram and describe each state.
Different process states are as follows:
1. New
2. Ready
3. Running
4. Waiting
5. Terminated
1. Ready: When the process is loaded into the main memory, it is ready for execution. In
this state the process is waiting for processor allocation.
2. Running: When CPU is available, system selects one process from main memory and
executes all the instructions from that process. So, when a process is in execution, it is
in running state. In single user system, only one process can be in the running state. In
multiuser system, there can be multiple processes which are in the running state.
3. Waiting State: When a process is in execution, it may request for I/O resources. If the
resource is not available, process goes into the waiting state. When the resource is
available, the process goes back to ready state.
4. Terminated State: When the process completes its execution, it goes into the
terminated state. In this state the memory occupied by the process is released.
1. Save Current State: The operating system saves the current state (context) of the
process being switched out, including registers, program counter, and memory pointers.
2. Restore New State: The operating system restores the saved state of the process being
switched in.
Overhead
Context switching incurs overhead due to:
7. Explain Thread with it’s any four benefits and it’s types
A thread is a lightweight process that runs concurrently with other threads within the same
process. Threads share the same memory space and resources, allowing for efficient
communication and data exchange.
A thread is a separate flow of execution within a process. It's a lightweight process that
shares the same memory space and resources as other threads in the same process.
Think of a thread like a mini-program that runs concurrently with other threads, allowing
for:
Concurrent execution
Improved responsiveness
Efficient resource usage
Benefits of Threads
Improved Responsiveness: Threads enable concurrent execution, allowing a program
to respond to user input and events while performing time-consuming tasks in the
background.
Increased Throughput: Multithreading can improve system utilization and
throughput by leveraging multiple CPU cores and executing tasks in
parallel.
Efficient Resource Usage: Threads share the same memory space, reducing the
overhead of creating and managing separate processes.
Simplified Programming: Threads can simplify programming by allowing
developers to write concurrent code that's easier to understand and
maintain.
TYPES OF THREADS
1. User-Level Threads:
In a user thread, all of the work of thread management is done by the application and the
kernel is not aware of the existence of threads.
The thread library contains code for creating and destroying threads, for passing message and
data between threads, for scheduling thread execution and for saving and restoring thread
contexts.
The application begins with a single thread and begins running in that thread. User level
threads are generally fast to create and manage.
1. Explain interprocess communication model (IPC) with it’s types in detail ( Shared
memory, Message Passing )
Inter-process communication: Cooperating processes require an Interprocess communication
(IPC) mechanism that will allow them to exchange data and information. There are two
models of IPC
1. Shared memory
1. In this, all processes who want to communicate with other processes can access a region of
the memory residing in an address space of a process creating a shared memory segment.
2. All the processes using the shared memory segment should attach to the address space of
the shared memory. All the processes can exchange information by reading and/or writing
data in shared memory segment.
3. The form of data and location are determined by these processes who want to communicate
with each other.
4. These processes are not under the control of the operating system.
5. The processes are also responsible for ensuring that they are not writing to the same
location simultaneously.
6. After establishing shared memory segment, all accesses to the shared memory segment are
treated as routine memory access and without assistance of kernel.
The many-to-one model maps many user-level threads to one kernel thread.
Thread management is done by the thread library in user space, so it is efficient; but
the entire process will block if a thread makes a blocking system call.
Also, because only one thread can access the kernel at a time, multiple threads are
unable to nm in parallel on multiprocessors.
Example: Green threads- a thread library available for Solaris
Advantages :
More concurrency because of multiple threads can run in parallel on multiple CPUs.
Less complication in the processing.
Disadvantages:
Thread creation involves light-weight process creation.
Kernel thread is an overhead.
Limiting the number of total threads.
Advantages:
Mainly used in language system, portable libraries.
One kernel thread controls multiple user thread.
Disadvantages:
Parallelism is not supported by this model.
One block can blocks all user threads.
Advantages:
Disadvantages:
True concurrency cannot be achieved.
Multiple threads of kernel is an overhead for operating system.
4. Explain deadlock
Deadlock is a situation where a set of processes are blocked because each process is
holding a resource and waiting for another resource held by another process.
5. What is priority scheduling?
In this scheduling, each process is assigned a priority. The CPU is allocated to the
process with the highest priority. If two processes have the same priority, they are
scheduled according to their arrival time
CPU burst cycle: It is a time period when process is busy with CPU.
I/O burst cycle: It is a time period when process is busy in working
with I/O resources.
A process execution consists of a cycle of CPU execution and I/O wait.
A process starts its execution when CPU is assigned to it, so process execution begins with
a CPU burst cycle.
This is followed by an I/O burst cycle when a process is busy doing I/O operations.
A process switch frequently from CPU burst cycle to I/O burst cycle and vice versa.
The complete execution of a process starts with CPU burst cycle, followed by I/O burst
cycle, then followed by another CPU burst cycle, then followed by another I/O burst cycle
and so on.
The final CPU burst cycle ends with a system request to terminate execution
Deadlock Prevention
Deadlock prevention ensures that at least one of the four conditions for deadlock is never allowed.
Techniques:
1. Mutual Exclusion:
o Not possible to eliminate for non-sharable resources like printers.
2. Hold and Wait:
o Require processes to request all resources at once, before execution starts.
o Drawback: Can lead to low resource utilization and starvation.
3. No Preemption:
o If a process is holding resources and requests another unavailable one, it must release all currently
held resources.
o Drawback: Leads to rollback and increased overhead.
4. Circular Wait:
o Impose a global order on resource types and require processes to request resources in an
increasing order of enumeration.
o Effective for static resource allocation systems.
Deadlock Avoidance
Deadlock avoidance allows the system to dynamically examine resource allocation and decide whether it
is safe to proceed.
Conditions:
The system must have prior knowledge of resource requirements (maximum demand) for each process.
Common Technique:
Banker’s Algorithm:
Checks whether granting a resource keeps the system in a safe state.
A state is safe if there exists a sequence of all processes such that each process can complete with
available + allocated resources.
Drawbacks:
Needs advance knowledge of maximum resources.
Can be complex and expensive to implement in real time.
Multilevel Queue Scheduling is a CPU scheduling algorithm that divides the ready queue
into multiple separate queues, each for a specific type of process. Each queue has its own
scheduling algorithm, and processes are permanently assigned to one queue based on
priority, memory size, process type, etc.
Key Features:
1. Processes are classified into different groups such as:
o System processes
o Interactive processes
o Batch processes
2. Each queue may use a different scheduling algorithm:
o Foreground queue: Round Robin
o Background queue: FCFS (First Come First Serve)
3. No movement between queues (processes stay in their assigned queue permanently).
4. Scheduling between queues can be based on:
o Fixed priority preemptive scheduling (e.g., always serve system queue
before user queue), or
o Time-slice rotation among queues.
Advantages:
Easy to implement scheduling policies for different process types.
High-priority tasks are handled quickly.
Disadvantages:
Starvation of low-priority processes (if high-priority queues are always full).
No dynamic movement between queues.
1. Preemptive Scheduling
Definition:
In preemptive scheduling, the CPU can be taken away from a process that is currently
executing if a higher priority process arrives or the time slice expires (in time-sharing
systems).
Key Features:
A process can be interrupted in the middle of execution.
Suitable for real-time and interactive systems.
More responsive but complex to implement.
Examples:
Round Robin (RR)
Shortest Remaining Time First (SRTF / SRTN)
Priority Scheduling (Preemptive)
Advantages:
Ensures better responsiveness for time-critical tasks.
CPU utilization is higher due to better task distribution.
Disadvantages:
Requires more context switching, leading to overhead.
Complex to implement and manage
2. Non-Preemptive Scheduling
Definition:
In non-preemptive scheduling, once a process is assigned the CPU, it keeps it until it
completes execution or voluntarily enters the waiting state.
Key Features:
Advantages:
Disadvantages:
Poor responsiveness.
A long job can block short, urgent jobs (i.e., leads to starvation).
i) SJF
ii) FCFS
Gantt Chart:
P1 P2 P4 P5 P3
0 7 11 17 25 35 (note: draw gannt chart in table form)
P1 0 7 7 7-0=7 7-7=0
P2 1 4 11 11 - 1 = 10 10 - 4 = 6
P4 3 6 17 17 - 3 = 14 14 - 6 = 8
P5 4 8 25 25 - 4 = 21 21 - 8 = 13
P3 2 10 35 35 - 2 = 33 33 -10 =
23
P1 0 7 11 11 - 0 = 11 11 - 7 = 4
P2 1 4 5 5-1=4 4-4=0
P4 3 6 17 17 - 3 = 14 14 - 6 = 8
P5 4 8 25 25 - 4 = 21 21 - 8 = 13
P3 2 10 35 35 - 2 = 33 33 -10 = 23
P1 0 7 7 7-0=7 7-7=0
P2 1 4 11 11 - 1 = 10 10 - 4 = 6
P3 2 10 21 21 - 2 = 19 19 -10 = 9
P4 3 6 27 27 - 3 = 24 24 - 6 = 18
P5 4 8 35 35 - 4 = 31 31 - 8 = 23
| P1 | P2 | P3 | P4 | P5 | P1 | P3 | P4 | P5 | P3 |
0 4 8 12 16 20 23 27 29 33 35
Process Table
Process Arrival Time Burst Time Completion Time Turnaround Time (CT - AT) Waiting Time (TAT - BT)
P1 0 7 23 23 - 0 = 23 23 - 7 = 16
P2 1 4 8 8-1=7 7-4=3
P3 2 10 35 35 - 2 = 33 33 -10 = 23
P4 3 6 29 29 - 3 = 26 26 - 6 = 20
P5 4 8 33 33 - 4 = 29 29 - 8 = 21
Average Calculations
NOTE:
2 Marks Questions
Fragmentation : When processes are loaded and removed from memory, the free memory
space is broken into little pieces which is known as fragmentation.
Page fault : A page fault is an interrupt that occurs when a process tries to access a page (a
block of memory) that is not currently in physical memory (RAM).
Page Faults Occur because the page is not loaded into RAM or the page was previously
swapped out to disk.
Types of partitioning :
1. Fixed partitioning :
Memory is divided into number of fixed size partitions, which is called as fixed or static
memory partitioning.
Each partition contains exactly one process.
The number of programs to be executed depends on number of partitions.
When the partition is free, a selected process from the input queue is loaded into the
free partition.
When the process terminates, the partition becomes available for another process .
The operating system keeps a table indicating parts of memory which are available and
which are occupied.
Initially, all memory is available for user processes and it is considered as one large
block of available memory, a hole.
When a process arrives, large enough hole of memory is allocated to the processes.
2. Variable partitioning :
When a process enters in main memory, it is allocated exact size that is required by
that process.
So in this method, partitions can vary in size depending on memory space required by
a process entering in main memory.
Operating system maintains a table indicating which parts of memory are available and
which are occupied.
When new process arrives and it needs space, system searches for available memory
space in main memory.
If it is available, then memory is allocated to the process by creating a partition in
memory.
1. Searches for free space: Looks for the first available partition that's large
enough to hold the process.
2. Allocates the process: Allocates the process to the first suitable partition.
1. Searches for largest available partition: Finds the largest partition available.
1. Paging :
Paging is the process of moving parts of a program, called pages, from secondary
storage (like a hard drive) into the main memory (RAM). The main idea behind
paging is to break a program into smaller fixed-size blocks called pages.
To keep track of where each page is stored in memory, the operating system uses a
page table. This table shows the connection between the logical page numbers (used
by the program) and the physical page frames (actual locations in RAM).
The memory management unit uses the page table to convert logical addresses into
physical addresses, so the program can access the correct data in memory.
2. Segmentation :
A process is divided into Segments. The chunks that a program is divided into which are not
necessarily all of the exact sizes are called segments.
Segmentation gives the user's view of the process which paging does not provide. Here the
user's view is mapped to physical memory.
Virtual Memory Segmentation: Each process is divided into a number of segments, but the
segmentation is not done all at once. This segmentation may or may not take place at the run
time of the program.
Simple Segmentation: Each process is divided into a number of segments, all of which are
loaded into memory at run time, though not necessarily contiguously.
1. Internal fragmentation :
Internal fragmentation happens when the memory is split into mounted-sized blocks.
Whenever a method is requested for the memory, the mounted-sized block is allotted
to the method.
In the case where the memory allotted to the method is somewhat larger than the
memory requested, then the difference between allotted and requested memory is
called internal fragmentation.
We fixed the sizes of the memory blocks, which has caused this issue. If we use
dynamic partitioning to allot space to the process, this issue can be solved.
2. External fragmentation :
External fragmentation happens when there's a sufficient quantity of area within the
memory to satisfy the memory request of a method.
However, the process’s memory request cannot be fulfilled because the memory
offered is in a non-contiguous manner.
Whether you apply a first-fit or best-fit memory allocation strategy it'll cause external
fragmentation
6 Marks Questions
1. Explain Free space management techniques ( Bit map, Linked List )
1. Bit Map :
The free-space list is implemented as a bit map or bit vector. Each block is represented
by 1 bit.
If the block is free, the bit is 1; if the block is allocated, the bit is 0.
The given instance of disk blocks on the disk in below Figure (where green blocks are
allocated) can be represented by a bitmap of 16 bits as:
1111000111111001.
2. Linked List :
In this approach, the free disk blocks are linked together i.e. a free block contains a pointer to
the next free block.
The block number of the very first disk block is stored at a separate location on disk and is
also cached in memory.
In below figure, the free space list head points to Block 5 which points to Block 6, the next
free block and so on.
The last free block would contain a null pointer indicating the end of free list. A drawback of
this method is the I/O required for free space list traversal.
Advantages:
The total available space is used efficiently using this method.
Dynamic allocation in Linked List is easy, thus can add the space as per the requirement
dynamically.
Disadvantages:
When the size of Linked List increases, the headache of miniating pointers is also increases.
This method is not efficient during iteration of each block of memory.
Virtual memory is a memory management technique used by operating systems to give the
appearance of a large, continuous block of memory to applications, even if the physical
memory (RAM) is limited. It allows larger applications to run on systems with less RAM.
The main objective of virtual memory is to support multiprogramming, The main advantage
that virtual memory provides is, a running process does not need to be entirely in memory.
Programs can be larger than the available physical memory. Virtual Memory provides an
abstraction of main memory, eliminating concerns about storage limitations.
A memory hierarchy, consisting of a computer system's memory and a disk, enables a process
to operate with only some portions of its address space in RAM to allow more processes to be
in memory.
Paging :
Paging divides memory into small fixed-size blocks called pages. When
the computer runs out of RAM, pages that aren't currently in use are moved
to the hard drive, into an area called a swap file.
The swap file acts as an extension of RAM. When a page is needed again,
it is swapped back into RAM, a process known as page swapping.
This ensures that the operating system (OS) and applications have enough
memory to run.
Basic Concept Divides memory into fixed-size Divides memory into variable-size
blocks called pages. blocks called segments.
Memory Both logical and physical memory are Logical memory is divided into
Division divided into equal-sized units. functional segments (e.g., code, stack).
Translation Uses a Page Table to map logical Uses a Segment Table to map segments
Table pages to physical frames. to memory addresses.
Example 1: Consider page reference string 1, 3, 0, 3, 5, 6, 3 with 3-page frames. Find the number of page faults
using FIFO Page Replacement Algorithm.
In this algorithm, pages are replaced which would not be used for the longest duration of time in the future.
Example: Consider the page references 7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 3 with 4-page frame. Find number of
page fault using Optimal Page Replacement Algorithm.
Example Consider the page reference string 7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 3 with 4-page frames. Find
number of page faults using LRU Page Replacement Algorithm.
Given a page reference string with three (03) page frames. Calculate the page faults with ‘Optimal’ and ‘LRU’
page replacement algorithm respectively. ‘7,0,1,2,0,3,0,4,2,3,0,3,2,1,2,0,1,7,0,1 (Representation of frame can be
in any order).
2 Marks Questions
1. Describe any four file attributes.
Name: The symbolic file name is the only information kept in human readable form.
Identifier: File system gives a unique tag or number that identifies file within file system and
which is used to refer files internally.
Type: This information is needed for those systems that support different types.
Location: This information is a pointer to a device and to the location of the file on that device.
Size: The current size of the file (in bytes, words or blocks) and possibly the maximum allowed
size are included in this attribute.
Protection: Access control information determines that who can do reading, writing, executing
and so on. Time, Date and User
Identification: This information may be kept for creation, Last modification and last use. These
data can be useful for protection, security and usage monitoring.
Creating a file
Writing a file
Reading a file Repositioning within a file
Deleting a file
Appending new information to the end of the file
Renaming an existing file
Truncating a file
Creating copy of a file, copy file to another I/O device such as printer or display
i. Contiguous
ii. Linked
iii. Indexed
File Attributes :
Name: The symbolic file name is the only information kept in human readable form.
Identifier: File system gives a unique tag or number that identifies file within file system and
which is used to refer files internally.
Type: This information is needed for those systems that support different types.
Location: This information is a pointer to a device and to the location of the file on that device.
Size: The current size of the file (in bytes, words or blocks) and possibly the maximum allowed
size are included in this attribute.
Protection: Access control information determines that who can do reading, writing, executing
and so on. Time, Date and User
Identification: This information may be kept for creation, Last modification and last use. These
data can be useful for protection, security and usage monitoring.
File Operations :
Creating a file
Writing a file
Reading a file Repositioning within a file
Deleting a file
Appending new information to the end of the file
Renaming an existing file
Truncating a file
Creating copy of a file, copy file to another I/O device such as printer or display
File Tpes :
Text Files: Contain plain text data, such as documents, source code, or configuration files (e.g.,
.txt,csv,ini).
Binary Files: Contain binary data, such as executable programs, images, audio, or video files
(e.g., .exe, .jpg, .mp3, .mp4).
Executable Files: Contain machine code that can be executed directly by the computer's
processor (e.g., .exe, .bin).
Data Files: Contain data used by applications, such as databases, spreadsheets, or documents
(e.g., .db, .xls, .docx).
System Files: Contain system-specific data or configuration information, such as device drivers
or system settings (e.g., .sys, .dll).
Archive Files: Contain compressed or archived data, such as zip files or tarballs (e.g., .zip, .tar,
.gz).
Image Files: Contain graphical data, such as pictures or graphics (e.g., .jpg, .png, .gif).
Audio Files: Contain audio data, such as music or sound effects (e.g., .mp3, .wav, .ogg).
Video Files: Contain video data, such as movies or animations (e.g., .mp4, .avi, .mov).
Information from the file is processed in order i.e. one record after another. It is commonly used
access mode.
For example, editors and compilers access files in sequence. A read operation read information
from the file in a sequence i.e. read next reads the next portion of the file and automatically
advances a file pointer.
A write operation writes information into the file in a sequence i.e. write next appends to the end
of the file and advances to the end of the newly written material.
Such a file can be reset to the beginning. In some operating systems, a program may be able to
skip forward or backward n records for some integer n.
As shown in above diagram, a file can be rewind (moved in forwward direction) from the
current position to start with beginning of the file or it can be read or write in forward direction.
From the user’s point of view, a file is an abstract data type. It can be created, opened, written,
read, closed and deleted without any real concern for its implementation.
The implementation of a file is a problem for the operating system. The main problem is how to
allocate space to these files so that disk space is effectively utilized and files can be quickly
accessed.
Three major methods of allocating disk space are in wide use:
Contiguous
Linked
Indexed
1. Contiguous Allocation :
The contiguous allocation method requires each file to occupy a set of contiguous addresses on
the disk. Disk addresses define a linear ordering on the disk. Contiguous allocation of a file is
defined by the disk address of the first block and its length. If the file is ‘n’ blocks long and
starts at location ‘b’, then it occupies blocks b, b+1, b+2,----------b+n-1. The directory entry for
each file indicates the address of the starting block and the length of the area allocated for this
file.
Contiguous allocation supports both sequential and direct access
For direct access to block ‘i’ of a file, which starts at block ‘b’, we can immediately access block
b+i. The difficulty with contiguous allocation is finding space for a new file.
For direct access to block ‘i’ of a file, which starts at block ‘b’, we can immediately access block
b+i.
The difficulty with contiguous allocation is finding space for a new file.
If file to be created are ‘n’ blocks long, we must search free space list for ‘n’ free contiguous
blocks.
Disadvantages :
Suffers from external fragmentation.
Very difficult to find contiguous blocks of space for new files.
Also with pre-allocation, it is necessary to declare the size of the file at the time of creation which
many a times is difficult to estimate.
Compaction may be required and it can be very expensive.
2. Linked List :
In this scheme, each file is a linked list of disk blocks which need not be contiguous.
The disk blocks can be scattered anywhere on the disk. The directory entry contains a pointer to
the starting and the ending file block.
Each block contains a pointer to the next block occupied by the file. The file 'jeep' in following
image shows how the blocks are randomly distributed. The last block (25) contains -1 indicating a
null pointer and does not point to any other block.
This is very flexible in terms of file size. File size can be increased easily since the system
does not have to look for a contiguous chunk of memory.
This method does not suffer from external fragmentation. This makes it relatively better in
terms of memory utilization.
Disadvantages:
Because the file blocks are distributed randomly on the disk, a large number of seeks are
needed to access every block individually. This makes linked allocation slower.
It does not support random or direct access. We can not directly access the blocks of a file. A
block k of a file can be accessed by traversing k blocks sequentially (sequential access ) from
the starting block of the file via block pointers.
Indexed Allocation :
In this scheme, a special block known as the Index block contains the pointers to all the
blocks occupied by a file.
Each file has its own index block. The ith entry in the index block contains the disk address of
the ith file block.
The directory entry contains the address of the index block as shown in the image:
2. Describe following directory structures in short with neat sketches: i) Single level ii) Two
level iii) Tree structured
Single level :
It is the simplest form of directory structure, having one directory containing all the files, and
each file must have a unique name.
Software design is simple. The advantages of this scheme are its simplicity and the ability to
locate files quickly.
Since all files are in the same directory, they must have unique names. If there are two users who
call their data file "test", then the unique-name rule is violated.
Even with a single-user, as the number of files increases, it becomes difficult to remember the
names of all the files in order to create files with unique name.
Two level :
In the two-level structures, each user has its own user file directory (UFD). The UFD lists only
files of a single user.
System contains a master file directory (MFD) which is indexed by user name or account number.
Each entry in MFD points to the UFD for that user.
When a user refers to a particular file, only his own UFD is searched. Different users can have
files with the same name, as long as all the file names within each UFD are unique.
In this directory structure user can create their own sub-directories and organize their files. The
tree has a root directory and every file has a unique path name.
A directory contains a set of files or subdirectories. All directories have the same internal format.
One bit in each directory entry defines the entry as a file (0) or as a subdirectory (1).
Each process has a current directory. Current directory contains files that are currently required by
the process.
When reference is made to a file, the current directory is searched. If a file needed that is not in
the current directory, then the user usually must either specify a path name or change the current
directory.