Unit 4
🔷 What is Disk Scheduling?
Q1 Explain the need of disk scheduling.
Disk scheduling refers to the method used by the operating system to determine the order
in which disk I/O requests are serviced.
When multiple processes request disk access, the OS places them in a queue and uses a
scheduling algorithm to decide the sequence of access.
🔷 Why is Disk Scheduling Needed?
Modern systems handle many simultaneous I/O operations, so efficient scheduling is critical for
performance.
🔹 1. Reduce Seek Time
● The seek time is the time taken by the disk arm to move to the track where data is
stored.
✅
● Efficient disk scheduling minimizes seek time by reordering requests intelligently.
Goal: Minimize the movement of read/write head to access disk blocks faster.
🔹 2. Improve Throughput
● By reducing the time to complete each I/O operation, more operations can be handled
per unit time.
✅
● This improves overall system throughput.
Goal: Maximize the number of completed disk requests per second.
🔹 3. Minimize Latency / Response Time
● Faster disk access improves the response time for users and applications.
✅
● Especially important in interactive or real-time systems.
Goal: Improve user experience and responsiveness.
🔹 4. Fairness Among Processes
● Disk scheduling ensures that no process waits indefinitely for disk access.
● Prevents starvation by servicing both large and small requests fairly.
✅ Goal: Maintain balanced and fair access to the disk.
🔹 5. Handle Burst of Requests
● In multitasking systems, many processes generate disk I/O at once.
● Disk scheduling manages these bursts efficiently to avoid bottlenecks.
✅ Goal: Efficiently manage high I/O load.
📌 Common Disk Scheduling Algorithms:
Algorithm Strategy
FCFS First-come, first-served
SSTF Shortest Seek Time First
SCAN Moves in one direction, then
reverses
C-SCAN One-direction scan, returns to start
✅ Conclusion:
LOOK / C-LOOK Like SCAN but stops at last request
Disk scheduling is essential for performance optimization in modern operating systems. It:
● Reduces disk access time
● Increases throughput
● Ensures fairness
● Enhances responsiveness
Q2 Explain any three types of disk scheduling with the help of suitable example.
✅ 1. FCFS – First-Come, First-Served🔹 Definition:
Processes are served in the order they arrive. No reordering is done.
🧠 Key Feature:
📌 Example:
● Simple & fair, but not always efficient.
Initial head position: 53
Request queue: 98, 183, 37, 122, 14, 124, 65, 67
🔧 Head movement:
53 → 98 → 183 → 37 → 122 → 14 → 124 → 65 → 67
➕ Total head movement:
|53-98| + |98-183| + |183-37| + ... = 640 cylinders
✅ 2. SSTF – Shortest Seek Time First🔹 Definition:
Selects the request closest to the current head position, minimizing seek time.
🧠 Key Feature:
● More efficient than FCFS.
📌 Example (Same as Above):
● May cause starvation of far requests.
Initial head position: 53
Request queue: 98, 183, 37, 122, 14, 124, 65, 67
🔧 Processing Order:
1. Closest to 53 → 65
2. Next closest to 65 → 67
3. Then 37 → 14 → 98 → 122 → 124 → 183
🕒 Movement:
53 → 65 → 67 → 37 → 14 → 98 → 122 → 124 → 183
➕ Total head movement:
= 236 cylinders (approx)
✅ 3. SCAN (Elevator Algorithm)🔹 Definition:
The head moves in one direction servicing all requests, and when it reaches the end, it
reverses direction.
🧠 Key Feature:
● Fairer and avoids starvation.
● Good performance balance.
● 📌 Example:
Initial head position: 53
Direction: Moving toward 0
Request queue: 98, 183, 37, 122, 14, 124, 65, 67
🔧 Reordered queue:
Sorted in direction of movement:
14, 37, 53, 65, 67, 98, 122, 124, 183
🕒 Head movement:
53 → 37 → 14 → (reaches end) → 65 → 67 → 98 → 122 → 124 → 183
➕ Total head movement:
= 208 + (back to 65 and onward) ≈ Total: 208 + 169 = 377 cylinders
📊 Comparison Summary:
Algorithm Strategy Pros Cons
FCFS Serve in arrival order Simple & fair May cause long delays
SSTF Closest request next Reduced total seek May cause starvation
time
SCAN Move in one direction, then Fair, avoids Can be slower than
reverse starvation SSTF
Q3 Explain the file allocation methods.
File allocation methods are strategies that an operating system (OS) uses to store files on a
storage device like a hard drive or SSD. These methods determine how files are placed in
memory or on disk, how data is retrieved, and how to handle fragmentation or inefficiencies. The
main goal is to organize the file system in a way that allows for fast access, efficient space
usage, and reliable data storage.
Here are the most common file allocation methods:
1. Contiguous Allocation
In contiguous allocation, each file occupies a single contiguous block of space on the disk. The
file is stored in one continuous region of the storage medium.
Advantages:
● Fast access: Since the file is stored in consecutive blocks, reading the file is
straightforward, and seek time is minimized.
● Simple and efficient: Easy to implement and manage.
Disadvantages:
● Fragmentation: As files are created, deleted, or resized, gaps (free space) might form
between files. Over time, fragmentation can make it difficult to allocate large contiguous
blocks for new files.
● Fixed size: The file system needs to know the maximum size of a file ahead of time. If a
file exceeds its allocated space, it may need to be relocated or resized, which can be
inefficient.
2. Linked Allocation
In linked allocation, files are stored as a chain of blocks scattered across the disk. Each block
contains a pointer to the next block, forming a linked list of blocks that together make up the file.
Advantages:
● No fragmentation: Since the blocks can be scattered, there's no need for large
contiguous free space. This reduces fragmentation.
● Dynamic file size: Files can grow or shrink dynamically because additional blocks can
be linked without requiring relocation.
Disadvantages:
● Slower access: To access a file, the system must follow the chain of pointers, which can
be slow, especially for large files.
● Overhead: Extra space is needed in each block to store the pointer to the next block,
which results in some overhead.
● Reliability issues: If a pointer is lost or corrupted, part of the file may become
inaccessible.
3. Indexed Allocation
In indexed allocation, a separate index block is created for each file. This index block contains
pointers to all the data blocks that store the file's content. This method allows files to be stored
in non-contiguous blocks, but the index block ensures that the system can quickly locate the
data blocks. Advantages:
● No fragmentation: Like linked allocation, files can be stored in non-contiguous blocks.
● Fast access: Unlike linked allocation, files can be accessed directly through the index
block, which eliminates the need to traverse chains of pointers.
● Flexibility: It supports dynamic file growth, and files don't need to be stored in a
contiguous region.
Disadvantages:
● Space overhead: Each file requires an additional block (the index block) to store
pointers to its data blocks.
● Fixed block size: The size of the index block can limit the number of blocks that can be
indexed, which can be problematic for very large files (although this can be addressed
with multi-level indexing).
4. Multi-Level Indexed Allocation
In multi-level indexed allocation, there are multiple levels of index blocks. The first-level index
block points to second-level index blocks, which in turn point to data blocks. This hierarchical
structure allows the file system to index very large files efficiently.
Advantages:
● Supports large files: It allows for indexing files larger than the limit of a single index
block by providing multiple levels of indirection.
● Efficient space utilization: It combines the benefits of indexed allocation while
supporting larger files.
Disadvantages:
● Complexity: Multi-level indexing introduces complexity in managing and accessing files.
● Overhead: Requires more blocks for storing index pointers at different levels, which
results in additional overhead
5. File Allocation Table (FAT)
The FAT method uses a table to maintain information about which disk blocks are allocated to
which files. The table keeps a record for each block on the disk, and it can be used to track file
fragments.
● Each entry in the table corresponds to a disk block and contains either a pointer to the
next block in the file or an indication that the block is free.
● FAT12, FAT16, and FAT32 are common implementations, where the number represents
the size of the pointers used to index blocks.
Advantages:
● Simple: Easy to understand and implement.
● Widely used: Works on various types of devices (USB drives, memory cards, etc.).
Disadvantages:
● Slow for large files: Searching through the table can be inefficient for very large files.
● Fragmentation: Files can become fragmented as they grow and shrink.
Summary Comparison:
Allocation Method Advantages Disadvantages
Contiguous Allocation Fast access, simple to Fragmentation, limited file size
manage flexibility
Linked Allocation No fragmentation, dynamic Slower access, overhead with
file size pointers
Indexed Allocation Fast access, no Overhead for index block, fixed
fragmentation, flexible block size limit
Multi-Level Indexed Supports large files, efficient Complexity, overhead for multiple
Allocation space use index levels
FAT Simple, widely supported Slow for large files, fragmentation
Each allocation method has its strengths and weaknesses, and the choice of method depends
on the requirements of the file system, such as performance, scalability, and ease of
implementation.
Q4 a) What is protection. How it differ from security.
b) Define File. List various attributes of a file. Also define them.
i) Protection vs Security
Protection and security are both related to safeguarding data, but they differ in scope,
purpose, and focus. Protection:Protection refers to mechanisms and policies
designed to control access to system resources such as files, memory, or devices. It is mainly
concerned with preventing unauthorized access, misuse, or modification of data by legitimate
users or processes within the system. Protection is typically enforced through:
● Access Control: Users or processes are assigned specific rights or permissions to
access system resources (e.g., read, write, execute).
● Privileges: Users or processes are granted specific levels of privilege based on their
roles or needs. For example, an administrator may have full access to all files, while a
regular user may have read-only access to certain files.
● Isolation: Keeping separate processes and users from interfering with each other's data
or resources.
Protection focuses on ensuring authorized users only perform operations they are allowed to.
Security:
Security, on the other hand, deals with the prevention of external threats or malicious
attacks such as hackers, viruses, or malware. Security aims to ensure that the system is
protected from unauthorized access by malicious users or external intruders. Key aspects of
security include:
● Confidentiality: Ensuring that sensitive data is only accessible to authorized individuals
(e.g., through encryption).
● Integrity: Ensuring that data is not altered or tampered with in an unauthorized manner
(e.g., checksums, hashes).
● Authentication: Verifying the identity of users and processes (e.g., passwords,
biometric scans).
● Non-repudiation: Ensuring that actions cannot be denied after they have been
performed (e.g., digital signatures).
Security focuses on protecting the system from external threats, while protection is more about
managing access control within the system.
Key Difference Between Protection and Security:
Aspect Protection Security
Purpose To ensure that legitimate users cannot To prevent unauthorized external access
misuse resources or attacks
Focus Internal users and processes' access External threats, malicious attacks, and
to resources vulnerabilities
Tools Access control, permissions, user Encryption, firewalls, authentication,
roles intrusion detection
Example A user having read-only access to a Preventing unauthorized users from
file accessing the system
ii) Definition of a File & Its Attributes
What is a File? A file is a collection of data or information that is stored on a storage
medium (e.g., hard drive, SSD). Files are used to store all types of data, including documents,
images, audio, video, programs, and more. They are the basic unit of storage in most file
systems and can be of different formats, such as text, binary, or multimedia.
Attributes of a File:
Files have various attributes that define their properties and help the operating system manage
them. Some common attributes include:
1. File Name:
○ Definition: The name given to a file, used to identify and locate the file in the file
system.
○ Example: report.txt, image.jpeg, data.csv
2. File Type:
○ Definition: A classification of the file that indicates its content or format. The file
type is often indicated by the file extension (e.g., .txt, .jpg).
○ Example: Text file, image file, audio file, executable file.
3. File Size:
○ Definition: The total amount of space the file occupies on the storage device,
usually measured in bytes.
○ Example: A file could be 1 KB, 10 MB, or 2 GB in size.
4. Creation Date:Definition: The date and time when the file was created.
○ Example: 2023-07-01 12:00:00
5. Last Accessed Date:
○ Definition: The most recent date and time the file was opened or read,
regardless of whether any changes were made.
○ Example: 2023-07-02 09:15:00
6. Last Modified Date:
○ Definition: The date and time when the contents of the file were last modified.
○ Example: 2023-07-02 10:00:00
7. File Owner:
○ Definition: The user or entity that owns the file. Ownership is typically associated
with user permissions and access control.
○ Example: UserA or root.
8. Permissions:
○ Definition: The access rights granted to users for reading, writing, or executing
the file. Permissions are typically divided into:
■ Read (r): Allows the user to view the file's contents.
■ Write (w): Allows the user to modify the file's contents.
■ Execute (x): Allows the user to run the file (for executable files).
○ Example: rw- (read and write, but not execute).
9. File Location (Address):
○ Definition: The actual physical or logical location of the file on the storage
device. It may refer to the path or directory where the file is stored.
○ Example: /home/user/documents/report.txt
10.File Attribute (Hidden, System, Archive):
● Definition: Special flags or attributes set for the file. For example, a file can be marked
as:
○ Hidden: The file is not displayed in directory listings.
○ System: The file is used by the operating system and should not be altered.
○ Archive: Marks the file for backup purposes.
● Example: hidden, system, archive.
11.File Compression:
● Definition: Indicates if the file is compressed to save storage space. Some file systems
provide automatic file compression.
● Example: .zip, .tar.gz
12.File Encryption:
● Definition: Indicates if the file’s contents are encrypted to protect the data from
unauthorized access.
● Example: A file may be encrypted using algorithms like AES (Advanced Encryption
Standard).
13.File Extension:
● Definition: The suffix at the end of a file name, usually indicating the file's format or
type.
● Example: .txt, .jpg, .exe.
14.File Locking:
● Definition: Indicates if a file is locked by a process, meaning that other processes
cannot modify it at that time.
● Example: Files may be locked by programs during use, like a text editor locking a file
while editing.
15.File System Information (Inode Information):
● Definition: In systems like UNIX/Linux, the inode stores metadata about a file, excluding
its name or actual data. It contains file permissions, owner information, size, and location
of the file blocks on the disk.
● Example: An inode number uniquely identifies a file on the disk.
Summary Table of File Attributes:
Attribute Definition Example
File Name The name given to the file for document.txt
identification.
File Type The type or format of the file. text, image, audio
File Size The total space the file occupies on 1 KB, 10 MB, 2 GB
storage.
Creation Date Date and time when the file was created. 2023-07-01 12:00:00
Last Accessed Date and time when the file was last 2023-07-02 09:15:00
Date accessed.
Last Modified Date and time when the file was last 2023-07-02 10:00:00
Date modified.
File Owner The user or entity that owns the file. UserA, root
Permissions The access rights granted to users for the rw- (read-write)
file.
File Location Path or directory location of the file. /home/user/docs/repor
t.txt
File Attribute Flags like hidden, system, archive, etc. hidden, system
File Indicates if the file is compressed. .zip, .tar.gz
Compression
File Encryption Whether the file is encrypted. Encrypted using AES
File Extension The file's suffix indicating its type. .txt, .jpg, .exe
File Locking Indicates if the file is currently locked. locked by process
Inode Metadata storage (in UNIX/Linux), inode number 12345
Information excluding file name.
These attributes help the operating system manage and access files efficiently while ensuring
proper control, security, and organization.
Q5 1. List down various protection problems that an operating system might have to
deal. 2. Differentiate between Linux and Windows operating systems.
1. Protection Problems in an Operating System
Protection in an operating system refers to mechanisms for controlling access to system
resources to ensure data integrity, privacy, and correct functioning. Here are various protection
problems an OS might face:
Protection Problem Description
Unauthorized Access Users or processes accessing data or resources without
permission.
Privilege Escalation A user or process gaining elevated access rights beyond what
is authorized.
Code or Data Alteration of system or user data/code by unauthorized
Modification entities.
Malware Infiltration Execution of malicious software that can compromise or
damage system integrity.
Resource Starvation Processes monopolizing system resources, denying access to
others.
Impersonation One process or user masquerading as another to gain access.
Denial of Service (DoS) Preventing legitimate users from accessing system resources.
Memory Protection A process accessing memory allocated to another process.
Violations
File System Access Improper permission settings allowing unauthorized file
Control access.
Race Conditions Exploiting timing issues in concurrent systems to gain
unauthorized access.
2. Difference Between Linux and Windows Operating Systems
Feature Linux Windows
Source Model Open-source Closed-source
Cost Generally free Paid (license required)
User Interface Command-line (bash) + GUI Primarily GUI (Explorer), CLI via
(GNOME, KDE, etc.) PowerShell/Command Prompt
Customization Highly customizable Limited customization
Security Generally more secure (due to Targeted more by malware; UAC for
permissions & open dev) protection
Software Excellent for open-source apps; Broad support for commercial and
Support limited for some proprietary proprietary software
software
File System ext4, Btrfs, XFS, etc. NTFS, FAT32
System Updates User-controlled updates Automatic or scheduled updates
Community Strong community-driven support Microsoft support & user forums
Support
Use Case Servers, development, Desktops, gaming, office
embedded systems, environments
cybersecurity
Q6
What is disk formatting. What basic information is stored with each sector. Describe
following disk scheduling algorithm with example: 1.FCFS 2.SSTF 3.Scan and
C-Scan 4.Look and C-Look
Disk Formatting and Disk Scheduling Algorithms
What is Disk Formatting?
Disk formatting is the process of preparing a storage device like a hard disk or SSD for initial
use. It creates a file system and divides the disk into sectors and tracks, allowing the
operating system to read and write data.
Types of Disk Formatting:
1. Low-Level Formatting: Organizes the disk into sectors and tracks (usually done by the
manufacturer).
2. High-Level Formatting: Creates the file system (e.g., NTFS, FAT32, ext4), allowing
data storage and retrieval.
Basic Information Stored in Each Sector:
Each sector (typically 512 bytes or 4KB) stores:
● Sector ID (address or number of the sector)
● Data (user or system data)
● Error Correction Code (ECC) (used to detect and correct errors)
● Control Information (e.g., synchronization data, sector markers)
Disk Scheduling Algorithms:
Disk scheduling algorithms decide the order in which disk I/O requests are serviced to minimize
seek time and improve performance.
Assume a disk with track requests at positions:
[98, 183, 37, 122, 14, 124, 65, 67]
Initial head position = 53
1. FCFS (First-Come, First-Served):
Requests are processed in the order they arrive.
Sequence:
53 → 98 → 183 → 37 → 122 → 14 → 124 → 65 → 67
Total Head Movement:
= |53-98| + |98-183| + |183-37| + |37-122| + |122-14| + |14-124| + |124-65| + |65-67|
= 45 + 85 + 146 + 85 + 108 + 110 + 59 + 2 = 640 tracks
2. SSTF (Shortest Seek Time First):
Selects the request closest to the current head position.
Sequence:
53 → 65 → 67 → 37 → 14 → 98 → 122 → 124 → 183
Total Head Movement:
= |53-65| + |65-67| + |67-37| + |37-14| + |14-98| + |98-122| + |122-124| + |124-183|
= 12 + 2 + 30 + 23 + 84 + 24 + 2 + 59 = 236 tracks
3. SCAN (Elevator Algorithm):
Head moves in one direction servicing all requests, then reverses at the end.
Assume movement towards higher tracks first.
Requests sorted: [14, 37, 65, 67, 98, 122, 124, 183]
Sequence:
53 → 65 → 67 → 98 → 122 → 124 → 183 → (end) → 37 → 14
Total Head Movement:
= |53-65| + |65-67| + |67-98| + |98-122| + |122-124| + |124-183| + |183-0| + |0-37| + |37-14|
= 12 + 2 + 31 + 24 + 2 + 59 + 183 + 37 + 23 = 373 tracks
4. C-SCAN (Circular SCAN):
Like SCAN, but after reaching the end, the head returns to the beginning without servicing in
reverse.
Sequence:
53 → 65 → 67 → 98 → 122 → 124 → 183 → (end) → (start) → 14 → 37
Total Head Movement:
= |53-65| + |65-67| + |67-98| + |98-122| + |122-124| + |124-183| + |183-199| + |0-14| + |14-37|
= 12 + 2 + 31 + 24 + 2 + 59 + 16 + 14 + 23 = 183 tracks
(Assuming disk size = 200 tracks)
5. LOOK:
Similar to SCAN but the head only goes as far as the last request in each direction before
reversing.
Sequence:
53 → 65 → 67 → 98 → 122 → 124 → 183 → 37 → 14
Total Head Movement:
= |53-65| + |65-67| + |67-98| + |98-122| + |122-124| + |124-183| + |183-37| + |37-14|
= 12 + 2 + 31 + 24 + 2 + 59 + 146 + 23 = 299 tracks
6. C-LOOK:
Similar to C-SCAN, but head returns only to the lowest request instead of the start.
Sequence:
53 → 65 → 67 → 98 → 122 → 124 → 183 → 14 → 37
Total Head Movement:
= |53-65| + |65-67| + |67-98| + |98-122| + |122-124| + |124-183| + |183-14| + |14-37|
= 12 + 2 + 31 + 24 + 2 + 59 + 169 + 23 = 322 tracks