CSE357 Workbook
CSE357 Workbook
1.2 Kernel
Definition: The core component of an operating system that provides essential services, such as process schedul-
ing, memory management, and device drivers. It directly interacts with the hardware.
Microkernel: A kernel architecture that keeps the core functions minimal, moving non-essential functions, such
as device drivers and file systems, to user space as separate processes. It enhances modularity but may incur
higher communication overhead.
Hybrid Kernel: A kernel that combines elements of both monolithic and microkernel designs. It includes
a small, efficient kernel core and places some traditional kernel functions in user space. This design aims to
achieve a balance between performance and modularity.
Exokernel: A kernel design that exposes the underlying hardware resources directly to applications, allowing
them to manage resources more efficiently. It offers fine-grained control over resources but places a greater
burden on application developers.
Nanokernel: An extremely lightweight kernel that handles only the most basic functions, such as process
scheduling and inter-process communication. It is designed for resource-constrained systems and focuses on
minimalism.
Real-Time Kernel: A kernel optimized for real-time systems, ensuring predictable and timely response to
external events. It prioritizes tasks based on their deadlines and is commonly used in applications like embedded
systems and robotics.
Hypervisor (Virtualization Kernel): A kernel designed for virtualization that allows multiple operating sys-
tems to run on the same physical hardware simultaneously. It manages virtual machines, allocating resources
and providing isolation between them.
Hurd Microkernel: The microkernel used in the GNU Hurd operating system. It follows a microkernel archi-
tecture, with core services running in user space and communication occurring through inter-process commu-
nication (IPC).
Windows NT Kernel: The kernel at the core of the Windows NT family of operating systems. It is a hy-
brid kernel that combines elements of monolithic and microkernel designs, providing features like preemptive
multitasking, security, and hardware abstraction.
Linux Kernel:
The core of the Linux operating system. It follows a monolithic architecture and provides essential services, in-
cluding process management, memory management, and device drivers. It is part of the broader Linux operating
system.
2
1.4 Process
(b). exec(): Replaces the current process’s memory image with a new one.
(c). wait(): Causes a process to wait until one of its child processes exits.
2. File Management System Calls:
(a). open(): Opens a file or device, creating a file descriptor.
(b). read(): Reads data from a file descriptor into a buffer.
(c). write(): Writes data from a buffer to a file descriptor.
(d). close(): Closes a file descriptor.
3. Device Management System Calls:
(a). ioctl(): Performs I/O control operations on devices.
(b). read(): Reads data from a device.
(c). write(): Writes data to a device.
4. Information Maintenance System Calls:
(a). getpid(): Returns the process ID of the calling process.
(b). getuid(): Returns the user ID of the calling process.
(c). time(): Returns the current time.
5. Communication System Calls:
(a). pipe(): Creates a communication pipe between two processes.
(b). msgget(), msgsnd(), msgrcv(): Create, send, and receive messages using message queues.
(c). semget(), semop(), semctl(): Create, perform operations on, and control semaphore sets.
6. Memory Management System Calls:
(a). brk(): Changes the end of the data (heap) segment of a process.
(b). mmap(): Maps files or devices into memory.
(c). munmap(): Unmaps files or devices from memory.
7. Network Communication System Calls:
(a). socket(): Creates a new communication endpoint (socket).
(b). bind(), listen(), accept(): Set up a server socket for network communication.
(c). connect(): Establishes a connection to a remote socket.
1.4 Process
Definition: A program in execution; it represents the basic unit of work in an operating system. Each process has
its own memory space and resources.
3
1.5 CPU Scheduling
Zombie Process: A process that has completed execution but still has an entry in the process table. Zombie
processes exist until their parent acknowledges their termination, after which they are removed from the system.
Critical Process: A process that is essential for the proper functioning of the system. Critical processes often
handle core system functions, and their failure can lead to system instability.
Interactive Process: A process that interacts directly with the user or responds to user input in real-time. Inter-
active processes often have a graphical user interface (GUI) or command-line interface for user interaction.
Batch Process: A process that is executed without direct user interaction. Batch processes are typically sched-
uled to run at specific times or in response to certain events, and they may process large volumes of data.
User-Level Process: A process that runs in user space rather than kernel space. User-level processes are subject
to user-level protection mechanisms and do not have direct access to hardware resources.
System-Level Process: A process that runs in kernel space and has privileged access to hardware resources.
System-level processes handle critical system functions and interact closely with the operating system kernel.
Cooperative Process: A process that voluntarily yields control to other processes, typically through cooperative
multitasking. Cooperative processes work together to share resources and execute tasks.
Preemptive Process: A process that can be interrupted or preempted by the operating system, allowing other
processes to run. Preemptive processes are essential for preemptive multitasking, ensuring fair CPU time allo-
cation.
Foreground Process: A process that actively interacts with the user and requires user input. It typically runs in
the foreground, and the user interface may be blocked until the process completes.
4
1.5 CPU Scheduling
Waiting
Figure 1.1: Process State Transition Diagram
5
1.6 Thread
1.6 Thread
Definition: A thread is the smallest unit of execution within a process. In a multi-threaded environment, a
process can be divided into multiple threads, each of which can independently execute code. Threads within the same
process share the same resources, including memory space, file descriptors, and other process-specific attributes.
Key characteristics of threads include:
Concurrency: Threads within a process can execute concurrently, allowing for parallelism and improved per-
formance.
Shared Resources: Threads in the same process share the same address space and resources, simplifying com-
munication and data sharing.
Lightweight: Threads are generally lightweight compared to processes, as they share resources and require less
overhead to create and manage.
Communication: Threads within a process can communicate through shared data or inter-thread communica-
tion mechanisms provided by the programming language or operating system.
Threads are commonly used to parallelize tasks, improve responsiveness in user interfaces, and optimize resource
utilization in multi-core systems.
6
1.7 Synchronization
3. Many-to-Many Model:
Description: Many user-level threads are multiplexed onto a smaller or equal number of kernel-level
threads. Both user-level and kernel-level threads can be scheduled independently. This model aims to
combine the efficiency of the many-to-one model with the parallelism of the one-to-one model.
Advantages: Balances efficiency and parallelism.
Disadvantages: Complexity in managing interactions between user-level and kernel-level threads.
4. Hybrid Model:
Description: Combines features of multiple thread models. For example, a system may use one-to-one
mapping for threads within a process and many-to-one mapping for threads across different processes.
Advantages: Provides flexibility in optimizing thread management for different scenarios.
Disadvantages: Can increase system complexity.
1.7 Synchronization
Process or thread synchronization is a mechanism employed in operating systems to control the access to shared
resources by multiple processes or threads. When multiple processes or threads run concurrently, there may be sce-
narios where they need to coordinate their activities to ensure proper execution and avoid conflicts. Synchronization
mechanisms help in achieving orderly and predictable execution of concurrent processes or threads.
7
1.7 Synchronization
Atomic Operations:
Atomic operations are those that are performed as a single, indivisible unit. In the context of synchronization,
atomic operations are often used to ensure that certain critical operations are executed without interruption.
Barrier:
A barrier is a synchronization construct that forces a group of processes or threads to wait until all members
of the group have reached a certain point in their execution before any of them proceeds.
Read-Write Lock:
A read-write lock allows multiple threads to read a shared resource concurrently, but only one thread can
write to the resource at a time. This is useful when reads do not modify the shared data.
Busy Waiting:
Busy waiting, also known as spinning or busy looping, is a synchronization technique where a process or
thread repeatedly checks for a condition to be true, without performing any significant work in the meantime.
Instead of yielding the processor or putting the process to sleep, the process continuously executes a tight
loop until the desired condition is met.
8
1.7 Synchronization
Explanation: This property ensures that progress is made even if multiple processes or threads are con-
tending for access to the critical section.
3. Bounded Waiting:
Desired Property: There exists a bound on the number of times that other processes or threads are allowed
to enter their critical sections after a process or thread has made a request to enter its critical section and
before that request is granted.
Explanation: This property prevents a process or thread from being indefinitely delayed in entering its
critical section, ensuring fairness in resource allocation.
9
1.8 Solution of Classical Synchronization Problems Using Semaphores/Mutex
6. Cigarette Smokers Problem: Involves three processes representing smokers with different ingredients and a
mediator. The challenge is to synchronize the processes so that a smoker with the right ingredients can smoke
only when the mediator provides them.
1.9 Deadlock
A deadlock is a situation in computing where two or more processes are unable to proceed because each is waiting
for the other to release a resource.
The occurrence of a deadlock requires the simultaneous satisfaction of four conditions, often known as the Coffman
conditions:
1. Mutual Exclusion: At least one resource must be held in a non-sharable mode. This means that only one process
at a time can use the resource.
10
1.9 Deadlock
11
1.9 Deadlock
2. Hold and Wait: A process must be holding at least one resource and waiting to acquire additional resources
that are currently held by other processes.
3. No Preemption: Resources cannot be forcibly taken away from a process; they can only be released voluntarily.
4. Circular Wait: There must be a circular chain of two or more processes, each waiting for a resource held by
the next one in the chain.
P1 R1
P2 R2
P3 R3
Figure 1.2: Resource Allocation Graph - Potential Deadlock
12
1.9 Deadlock
13
1.10 Types of Memory
14
1.10 Types of Memory
ROM (Read-Only Memory): Non-volatile memory that contains firmware or permanent software in-
structions. The data in ROM is typically not modified during normal operation.
2. Secondary Memory (Storage Devices)
Hard Disk Drives (HDD): Non-volatile data storage devices with high capacity for long-term storage.
Slower access compared to RAM.
Solid State Drives (SSD): Non-volatile storage devices that use NAND-based flash memory for faster data
access than HDDs.
Flash Drives (USB Drives): Portable and non-volatile storage devices using NAND flash memory.
Optical Drives (CDs, DVDs, Blu-rays): Non-volatile storage devices that use optical technology to read
and write data.
3. Cache Memory L1, L2, and L3 Cache: Small-sized, high-speed memory units located directly on or near the
CPU. They store frequently accessed instructions and data for faster retrieval.
4. Registers
CPU Registers: Fast, small-sized storage locations within the CPU. They store data, addresses, and intermediate
results during program execution. Different types of registers serve various purposes in a computer system. Here
are some common types of registers:
Data Register (DR): Also known as the accumulator, the data register is used for storing intermediate data
during arithmetic and logic operations. It’s often the primary register for arithmetic calculations.
Address Register (AR): The address register holds the memory address of the data that needs to be ac-
15
1.11 Memory Management Schemes
Process
Page Table
Virtual
Page Fault
Memory
Handler
Physical
Memory Disk
(RAM)
Figure 1.6: Virtual Memory Representation
16
1.11 Memory Management Schemes
Advantages:
Simple and easy to implement.
No external fragmentation.
Disadvantages:
Inflexible for varying memory requirements.
Internal fragmentation can occur if a partition is larger than the size of the process.
17
1.11 Memory Management Schemes
1.11.3 Paging:
Description: Memory is divided into fixed-size blocks called pages. Processes are divided into fixed-size blocks
as well. Pages of a process do not need to be contiguous in physical memory.
Advantages:
Reduces external fragmentation.
Simplifies memory management.
Disadvantages:
May suffer from internal fragmentation within pages.
Requires a page table for address translation.
18
1.11 Memory Management Schemes
Logical Address
(Page Number, Offset)
Page Table
Look up Page Table
19
1.11 Memory Management Schemes
Logical Address
(Page Number, Offset)
20
1.11 Memory Management Schemes
When a page is shared among multiple processes, the operating system uses a copy-on-write strategy. Initially,
the pages are shared, and if one process attempts to modify the content of a shared page, a copy of that page is
created for the modifying process.
21
1.11 Memory Management Schemes
22
1.11 Memory Management Schemes
CPU
TLB
1.11.4 Segmentation:
Description: Memory is divided into logical segments based on the program’s structure (e.g., code segment, data
segment). Segments do not need to be contiguous in physical memory.
Process Segments
Code Segment
Data Segment
Stack Segment
Heap Segment
Advantages:
Supports dynamic memory allocation.
Provides a logical structure to memory.
Disadvantages:
May suffer from fragmentation within segments.
More complex than paging.
23
1.11 Memory Management Schemes
Logical Address
(Segment Number, Offset)
Segment Table
Look up Segment Table
Calculate Seg-
ment Base Address
24
1.12 Secondary Storage
Logical Address
(Segment Number, Page Number, Offset)
Segment Table
25
1.13 RAID (Redundant Array of Independent Disks)
File System
Files Directories Metadata File Operations Access Control Naming Conventions Attributes
Figure 1.14: A File System
26
1.14 File System
1.14.0.2 Inode
An inode, short for ”index node,” is a data structure used in Unix-like file systems to store information about a
file or a directory. Each file or directory in the file system is associated with a unique inode, and the inode contains
metadata about the file or directory rather than the actual data. The inode serves as an index or reference to the actual
data blocks on the disk where the file’s content is stored.
Key information stored in an inode typically includes:
1. File Type: Indicates whether the inode refers to a regular file, directory, symbolic link, or other file types.
2. File Permissions: Specifies the access permissions (read, write, execute) for the file owner, group, and others.
3. Owner Information: Identifies the user (user ID) who owns the file.
4. Group Information: Identifies the group (group ID) associated with the file.
5. File Size: Specifies the size of the file in bytes.
6. Timestamps: Records various timestamps, including the time the file was created, last modified, and last ac-
cessed.
7. Number of Links: Indicates the number of hard links pointing to the inode. When a file has multiple hard links,
they share the same inode.
8. Pointers to Data Blocks: Stores pointers or references to the actual data blocks on the disk where the file content
is stored. For small files, these pointers may directly reference the data blocks. For larger files, additional indirect
blocks may be used.
27
1.15 Disc Scheduling
28
1.16 Important Linux Commands
Basic Commands
File Handling
Processes
29
1.16 Important Linux Commands
System Information
Package Management
Networking
30
1.16 Important Linux Commands
System Logs
File System
31
1.16 Important Linux Commands
Shell Scripting
Security
CPU Scheduling
1. Turnaround Time:
(a). T urnaround T ime = Completion T ime − Arrival T ime
(b). T urnaround T ime = Waiting Time + Burst Time
2. Waiting Time: W aiting T ime = T urnaround T ime − Burst T ime
3. Response Time:
The time from submitting a request until the first response is produced.
Response Time = Time of First Response − Arrival Time
4. Throughput: Throughput = Number of Total
processes completed
time
5. CPU Utilization: CPU Utilization = Total CPU time
Total time ×∑100%
6. Average Waiting Time: Average Waiting Time = (Waiting Time of each process)
Number of processes
∑
(Turnaround Time of each process)
7. Average Turnaround Time: Average Turnaround Time = Number of processes
∑
(Response Time of each process)
8. Average Response Time: Average Response Time = Number of processes
Memory Management
1. Effective Access Time (EAT):
(a). EAT = (1 − p) × Memory Access Time + p × Page Fault Rate × Page Fault Service Time
(b). EAT = Hit Ratio×Memory Access Time (Cache)+Miss Ratio×Memory Access Time (Main Memory)
2. Degree of Multiprogramming: Degree of M ultiprogramming = Number of Processes in Main Memory
Total Number of Processes × 100%
3. Memory Access Time: M emory Access T ime = Memory Access Time (RAM)+Memory Transfer Time (if applicabl
4. Memory Cycle Time: M emory Cycle T ime = Memory Access Time + Time to complete one cycle
5. Page Table Size: P age T able Size = Size of Logical Address Space
Page Size
6. Internal Fragmentation: Internal F ragmentation = Partition Size − Process Size
7. External Fragmentation: External F ragmentation = Total Free Memory − Largest Free Block
Number of Page Faults
8. Page Fault Rate (PFR): P age F ault Rate = Number of Memory Accesses
9. Memory Mapping Overhead:
M emory M apping Overhead = Size of Logical Address Space − Size of Physical Address Space
File Systems
1. Disk Access Time: Disk Access T ime = Seek T ime + Rotational Latency + T ransf er T ime
2. File Allocation Table (FAT): A table that maps file clusters to disk blocks.
Block Size
3. File Organization: Records per Block = Record Size
33
1.16 Important Linux Commands
34
1.17 Frequently Asked Interview Questions
35
1.17 Frequently Asked Interview Questions
45. Define the terms logical clock and physical clock in distributed systems.
46. Define the terms mutual exclusion and race condition.
47. Define the terms NUMA (Non-Uniform Memory Access) and UMA (Uniform Memory Access).
48. Define the terms parallel processing and distributed processing.
49. Define the terms preemptive and non-preemptive kernel.
50. Define the terms preemptive and non-preemptive multitasking.
51. Define the terms preemptive and non-preemptive scheduling.
52. Define the terms priority inversion and priority inheritance in scheduling.
53. Define the terms process group and session in process management.
54. Define the terms process group and session.
55. Define the terms process priority and process scheduling priority.
56. Define the terms process spawning and process termination in process management.
57. Define the terms process spawning and process termination.
58. Define the terms process synchronization and interprocess communication (IPC).
59. Define the terms resource allocation graph and deadlock cycle.
60. Define the terms response time and turnaround time.
61. Define the terms semaphores and mutex.
62. Define the terms spin lock and mutex.
63. Define the terms starvation and aging in process scheduling.
64. Define the terms starvation and aging in scheduling.
65. Define the terms strong and weak consistency.
66. Define the terms strong consistency and weak consistency in distributed systems.
67. Define the terms superblock and inode in file systems.
68. Define the terms symmetric multiprocessing (SMP) and asymmetric multiprocessing.
69. Define the terms symmetrical multiprocessing (SMP) and asymmetrical multiprocessing.
70. Define the terms system image backup and incremental backup.
71. Define the terms task and process in an operating system.
72. Define the terms throughput and bandwidth.
73. Define the terms throughput and latency.
74. Define the terms throughput and turnaround time.
75. Define the terms time-sharing and space-sharing in resource allocation.
76. Define the terms token ring and Ethernet in the context of networking.
77. Define the terms transparent and explicit file access.
78. Define the terms user mode and kernel mode in CPU operation.
79. Define the terms voluntary and involuntary context switch in scheduling.
80. Define the terms voluntary and involuntary context switch.
81. Define the terms weak and strong consistency in distributed systems.
82. Define thrashing and its effects on system performance.
83. Define thread synchronization.
84. Define virtualization.
85. Differentiate between a process and a program.
86. Differentiate between internal and external fragmentation.
87. Differentiate between process and thread.
88. Differentiate between user-level threads and kernel-level threads.
89. Explain the concept of a command interpreter or shell.
90. Explain the concept of a condition variable in process synchronization.
36
1.17 Frequently Asked Interview Questions
37
1.17 Frequently Asked Interview Questions
38
1.17 Frequently Asked Interview Questions
39
1.17 Frequently Asked Interview Questions
40
1.18 Worksheets
1.18 Worksheets
Worksheet 1
41
1.18 Worksheets
9. In the context of operating systems, which statement accurately describes a characteristic of microkernels?
A. Microkernels generally have a larger kernel size compared to monolithic kernels.
B. Microkernels move most of the operating system services into kernel space.
C. Microkernels provide higher performance due to reduced inter-process communication.
D. Microkernels emphasize minimalism, with essential services implemented as user-level processes.
10. What is the primary goal of multiprogramming in operating systems?
A. To improve the performance of a single program
B. To execute multiple programs concurrently for better CPU utilization
C. To simplify the user interface
D. To reduce the size of the operating system
Subjective Questions
1. Compare and contrast the characteristics of real-time operating systems (RTOS) and general-purpose operating
systems.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
2. Discuss the differences between microkernels and monolithic kernels. Evaluate the strengths and weaknesses of
each architecture and provide examples of operating systems that use each type of kernel.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
3. Describe the booting process of an operating system. Include the role of the bootloader and the initialization of
the kernel.
....................................................................................................
....................................................................................................
....................................................................................................
42
1.18 Worksheets
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
4. Explain the role of device drivers in an operating system and how they facilitate communication between software
and hardware.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
5. Describe the purpose and functionality of system calls in an operating system. Provide examples of common
system calls.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
6. Explain the concept of interrupts in the context of computer systems.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
43
1.18 Worksheets
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
44
1.18 Worksheets
Worksheet 2
45
1.18 Worksheets
Subjective Questions
1. Explain the concept of a process in operating systems. Highlight the key components of a process and the role
they play in program execution.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
2. Describe the life cycle of a process. Discuss the transitions between different states and the events triggering
these transitions.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
46
1.18 Worksheets
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
3. Compare and contrast preemptive and non-preemptive CPU scheduling algorithms. Provide examples of sce-
narios where each type of algorithm is beneficial.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
4. Define the term ”thread” in the context of multitasking. Explain the advantages of using threads over processes
and how they contribute to parallelism.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
5. Explain the difference between user-level threads (ULTs) and kernel-level threads (KLTs). Discuss the advan-
tages and disadvantages of each type and scenarios where they are most suitable.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
47
1.18 Worksheets
....................................................................................................
6. Consider a system with three processes scheduled using the Round Robin (RR) scheduling algorithm. The time
quantum is set to 4 milliseconds. The arrival time and burst time for each process are as follows:
48
1.18 Worksheets
Worksheet 3
49
1.18 Worksheets
Subjective Questions
1. Explain the concept of synchronization in operating systems. Why is it essential for concurrent program execu-
tion, and what challenges does it address?
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
2. Define the critical section problem and explain why it is a fundamental concern in concurrent programming.
Describe the requirements that a solution to the critical section problem must satisfy.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
3. Define deadlock in the context of operating systems. Discuss the necessary conditions for deadlock occurrence
and how they contribute to the formation of a deadlock.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
50
1.18 Worksheets
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
4. Explain the difference between deadlock prevention and deadlock avoidance strategies.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
5. A system has three processes with the following burst times (in milliseconds) and priorities:
Assuming Priority scheduling algorithm, calculate the average waiting time and average turnaround time.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
6. Consider a system with five processes (P 1, P 2, P 3, P 4, and P 5) and three resource types (A, B, and C). The
current allocation matrix, maximum demand matrix, and available matrix are given as follows:
51
1.18 Worksheets
52
1.18 Worksheets
Worksheet 4
53
1.18 Worksheets
D. Simplicity of implementation
9: Which of the following is a primary purpose of RAID technology?
A. Disk Encryption
B. Improved File Compression
C. Increased Data Redundancy and Fault Tolerance
D. Enhanced Disk Formatting
10: In a paging system, if the logical address space is divided into pages of size 212 bytes and the physical memory
is divided into frames of the same size, how many bits are needed for the page number and the offset within the
page, respectively, for a 32-bit logical address?
A. 20 bits for page number, 12 bits for offset
B. 10 bits for page number, 22 bits for offset
C. 12 bits for page number, 20 bits for offset
D. 14 bits for page number, 18 bits for offset
Subjective Questions
1. Explain the working principles of the Least Recently Used (LRU) page replacement algorithm. Discuss its
advantages and potential drawbacks. Can you suggest scenarios where LRU might perform exceptionally well
or poorly?
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
2. Explain the structure of a disk in detail, including the terms like tracks, sectors, and cylinders. How do these
components contribute to efficient data storage and retrieval on a disk?
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
3. Discuss the advantages and disadvantages of disk partitioning in terms of organization and performance. How
54
1.18 Worksheets
does partitioning contribute to disk management and data security in an operating system?
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
4. Consider the following scenario:
Page Reference String: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5
Number of Page Frames: 3
Use the Least Recently Used (LRU) page replacement algorithm to calculate the number of page faults.
LRU Page Replacement Algorithm:
Initially, all page frames are empty.
When a page is referenced:
If the page is already in a frame, it becomes the most recently used.
If the page is not in any frame, a page fault occurs, and the least recently used page is replaced.
Question:
Calculate the number of page faults using the LRU page replacement algorithm for the given page reference
string and a total of 3 page frames.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
5. Provide an overview of what RAID is and describe at least three common RAID levels (e.g., RAID 0, RAID 1,
RAID 5).
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
55
1.18 Worksheets
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
6. Consider a disk with 100 tracks numbered from 0 to 99. The current position of the disk arm is at track 50. The
following disk access requests are given:
Assuming the SSTF (Shortest Seek Time First) disk scheduling algorithm, calculate the total head movement
using the current disk arm position.
Solution Steps:
(a). Calculate the absolute seek time for each request by finding the absolute difference between the current
position and the requested track.
(b). Select the request with the shortest seek time and move the disk arm to that track.
(c). Repeat steps 1 and 2 until all requests are processed, and calculate the total head movement.
Provide the final total head movement as the answer.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
56
Appendix A Important Algorithms
A.2 Shortest Job Next (SJN) or Shortest Job First (SJF) CPU Scheduling
Algorithm 6 Shortest Job Next (SJN) or Shortest Job First (SJF) CPU Scheduling
1: Initialize the queue to store processes.
2: Insert all processes into the queue.
3: while the queue is not empty do
4: Sort the queue based on the burst time of each process in ascending order.
5: Dequeue the process with the shortest burst time.
6: Set the start_time of the process as the maximum of its arrival time and the current time.
7: Execute the process until completion.
8: Update the current time to the end time of the dequeued process.
9: Calculate the turnaround time and waiting time for each process:
10: Turnaround Time (TAT) = Completion Time - Arrival Time
11: Waiting Time (WT) = Turnaround Time - Burst Time
12: Calculate the average turnaround time and average waiting time for all processes.
13: Display the turnaround time, waiting time, and average values for analysis.
A.3 Priority Scheduling CPU Scheduling
58
A.3 Priority Scheduling CPU Scheduling
59
A.3 Priority Scheduling CPU Scheduling
60