INDIRA GANDHI DELHI TECHNICAL
UNIVERSITY FOR WOMEN
OPERATING SYSTEM
BIT-202
Submitted by:- Submitted to:-
Name: Kiran Kumari Dr. Vijay Kumar
Enrollment No: 10001012023 (CSE Department)
Batch: CSE-2, A2 (2023-27) IGDTUW
B.Tech, 4th Semester
INDEX
Exp. Experiment Title Date
No.
1. To implement Linux commands. 16/01/25
2. To understand system calls of an operating 23/01/25
system.
3. To implement First Come First Serve (FCFS) 30/01/25
scheduling algorithm.
4. To implement Shortest Job First (SJF) scheduling 06/02/25
algorithm.
5. To implement Shortest Remaining Time First 20/02/25
(SRTF) scheduling algorithm.
6. To implement Round Robin (RR) scheduling 20/02/25
algorithm.
7. To implement non-preemptive priority scheduling 20/03/25
algorithm.
8. To implement preemptive priority scheduling 27/03/25
algorithm.
9. To implement Banker’s Algorithm 17/04/25
EXPERIMENT 1
IMPLEMENTATION OF LINUX COMMANDS
Objective:
To study and execute basic Linux terminal commands related to file handling, directory
structure, process management, and file permissions.
Software/Hardware Requirements:
• Linux terminal or any Unix-based terminal
• System with user access
Theory:
The Linux terminal allows users to interact with the operating system using command-line
tools. These commands help manage files, directories, processes, and user information
efficiently. Understanding these commands is essential for effective system-level operations.
Procedure:
Open the terminal and run the following commands step-by-step:
1. Directory Navigation
2. Creating and Listing Files
3. Writing and Viewing File Content
4. Copying, Renaming, and Deleting Files
5. Changing File Permissions
6. Process Management
7. User Information
List of Commonly Used Linux Commands:
àFile and Directory Commands
pwd Show present working directory
ls List files and directories
ls -l Long listing with details
cd dir_name Change directory
mkdir dir_name Create a new directory
rmdir dir_name Remove empty directory
rm -r dir_name Remove directory and contents
touch filename Create an empty file
cp source dest Copy file or directory
mv old new Rename or move file/directory
rm filename Delete file
clear Clear terminal screen
àFile Content Commands
echo “text” Print text to terminal
echo “text” > file Write text to file
cat filename Display file content
more filename Show file content page-wise
less filename Like more
head filename Show first 10 lines
tail filename Show last 10 lines
nano filename Open file in nano editor
vi filename Open file in vi editor
àFile Permissions and Ownership
ls -l Show file permissions
chmod 755 file Change file permissions
chown user:group file Change file owner and group
àProcess Management
ps List running processes
top Real-time process monitoring
kill PID Kill process by PID
killall name Kill all processes by name
sleep 5 Wait 5 seconds
àUser and System Info
whoami Show current user
who Who is logged in
id Show user ID/group ID
hostname Show system hostname
date Current date and time
uptime Show system uptime
Result:
The basic Linux terminal commands were successfully executed. File operations, permission
modifications, and process monitoring were carried out as per the procedure.
EXPERIMENT 2
SYSTEM CALLS IN OPERATING SYSTEMS
Objective:
To understand and implement basic system calls in an operating system using the C++
programming language.
Introduction to System Calls
System calls serve as an interface between user applications and the operating system kernel.
When a program needs to perform operations such as file handling, process creation, or
communication, it uses system calls to request these services from the OS.
System calls provide controlled access to system resources, ensuring security and efficiency.
Common categories of system calls include:
• Process Control: fork(), exec(), exit(), wait()
• File Management: open(), read(), write(), close()
• Device Management: ioctl(), read(), write()
• Information Maintenance: getpid(), getppid(), alarm()
• Communication: pipe(), shmget(), msgget()
Theory and Explanation of Key System Calls
1. fork() System Call
The fork() system call creates a new process, called the child process, which is a copy of the
parent process.
• Return Value:
o 0 for the child process
o > 0 for the parent process (returns the child's PID)
o < 0 if the process creation fails
2. getpid() and getppid() System Calls
• getpid() returns the process ID (PID) of the calling process.
• getppid() returns the parent process ID (PPID) of the calling process.
3. exit() System Call
The exit() system call terminates a process and releases its allocated resources.
4. wait() System Call
The wait() system call suspends the execution of a parent process until one of its child
processes completes.
5. exec() System Call
The exec() family of functions replaces the current process image with a new program.
6. open(), read(), write(), and close() System Calls
• open() is used to open a file.
• read() reads data from a file.
• write() writes data to a file.
• close() closes the file descriptor.
Implementation of System Calls in C++
1.Basic Process Control using fork(), getpid(), and getppid()
2.Using exit() System Call
3.Using wait() System Call
4. Using exec() System Call
5. File Handling using open(), read(), write(), and close() System Calls
5. Conclusion
• System calls provide controlled access to the operating system and hardware
resources.
• The fork() system call enables process creation.
• The getpid() and getppid() system calls retrieve process-related information.
• The exit() system call allows for proper process termination.
• The wait() system call ensures that a parent process waits for its child process to
complete.
• The exec() system call replaces a process image with a new program.
• File system calls such as open(), read(), write(), and close() handle file operations.
• Understanding system calls is essential for OS-level programming and process
management.
EXPERIMENT 3
FIRST COME FIRST SERVE (FCFS) SCHEDULING
Objective:
To understand and implement the First Come First Serve (FCFS) scheduling algorithm in
an operating system.
Introduction to FCFS Scheduling
First Come First Serve (FCFS) is the simplest CPU scheduling algorithm, where
processes are executed in the order they arrive.
Characteristics of FCFS:
• Non-Preemptive: Once a process starts execution, it runs till completion.
• FIFO (First In, First Out) approach.
• Convoy Effect: Long processes delay short ones.
Advantages:
i. Simple to implement.
ii. Works well when process execution times are similar.
Disadvantages:
i. Not efficient for time-sharing systems.
ii. Convoy effect increases average waiting time.
Example of FCFS Scheduling
Given Processes:
Process Arrival Time Burst Time
P1 0 ms 5 ms
P2 1 ms 3 ms
P3 2 ms 8 ms
Gantt Chart Representation:
| P1 | P2 | P3 |
0 5 8 16
• Completion Time (CT):
o P1 = 5 ms
o P2 = 8 ms
o P3 = 16 ms
• Turnaround Time (TAT) = Completion Time - Arrival Time
o P1 = 5 - 0 = 5 ms
o P2 = 8 - 1 = 7 ms
o P3 = 16 - 2 = 14 ms
• Waiting Time (WT) = Turnaround Time - Burst Time
o P1 = 5 - 5 = 0 ms
o P2 = 7 - 3 = 4 ms
o P3 = 14 - 8 = 6 ms
Average Waiting Time (AWT):
AWT=(0+4+6)/3=10/3=3.33 ms
FCFS Scheduling Algorithm Implementation in C++
Conclusion
• FCFS is a simple and easy-to-implement scheduling algorithm.
• It can cause long waiting times due to the Convoy Effect.
• Useful in batch systems but inefficient in interactive environments.
EXPERIMENT 4
SHORTEST JOB FIRST (SJF) SCHEDULING
Objective:
To understand and implement the Shortest Job First (SJF) scheduling algorithm in an
operating system.
Introduction to SJF Scheduling
The Shortest Job First (SJF) scheduling algorithm selects the process with the shortest
burst time for execution.
Types of SJF Scheduling:
• Non-Preemptive SJF: Once a process starts execution, it runs till completion.
• Preemptive SJF (Shortest Remaining Time First - SRTF): If a new process arrives
with a shorter burst time than the currently executing process, the CPU is preempted.
Advantages:
i. Minimizes average waiting time compared to FCFS.
ii. Efficient for batch systems where process execution times are known.
Disadvantages:
i. Starvation can occur if shorter processes keep arriving, delaying longer ones.
ii. Not ideal for real-time systems due to unpredictable execution times.
Example of SJF (Non-Preemptive) Scheduling
Given Processes:
Process Arrival Time Burst Time
P1 0 ms 7 ms
P2 2 ms 4 ms
P3 4 ms 1 ms
P4 5 ms 3 ms
Execution Order (Gantt Chart):
| P1 | P3 | P4 | P2 |
0 7 8 11 15
• Completion Time (CT):
o P1 = 7 ms
o P3 = 8 ms
o P4 = 11 ms
o P2 = 15 ms
• Turnaround Time (TAT) = Completion Time - Arrival Time
o P1 = 7 - 0 = 7 ms
o P2 = 15 - 2 = 13 ms
o P3 = 8 - 4 = 4 ms
o P4 = 11 - 5 = 6 ms
• Waiting Time (WT) = Turnaround Time - Burst Time
o P1 = 7 - 7 = 0 ms
o P2 = 13 - 4 = 9 ms
o P3 = 4 - 1 = 3 ms
o P4 = 6 - 3 = 3 ms
Average Waiting Time (AWT):
AWT=(0+9+3+3)/4 = 15/4 = 3.75ms
Implementation of SJF (Non-Preemptive) in C++
Conclusion
• SJF is optimal for minimizing average waiting time.
• It may cause starvation if new short processes keep arriving.
• Preemptive SJF (SRTF) solves some starvation issues but increases overhead
EXPERIMENT 5
SHORTEST REMAINING TIME FIRST (SRTF) SCHEDULING
Objective:
To understand and implement the Shortest Remaining Time First (SRTF) scheduling
algorithm in an operating system.
Introduction to SRTF Scheduling
The Shortest Remaining Time First (SRTF) algorithm is the preemptive version of
Shortest Job First (SJF) scheduling.
Characteristics of SRTF:
• Preemptive: If a new process arrives with a shorter burst time than the remaining
time of the current process, the CPU is preempted.
• More efficient than non-preemptive SJF in reducing waiting time.
• Can lead to starvation if shorter processes keep arriving.
Advantages:
i. Minimizes average waiting time better than FCFS & SJF.
ii. Ensures better CPU utilization as shorter processes finish quickly.
Disadvantages:
i. Complex to implement due to frequent context switching.
ii. Starvation risk for long processes if short jobs keep arriving.
Example of SRTF Scheduling
Given Processes:
Process Arrival Time Burst Time
P1 0 ms 8 ms
P2 1 ms 4 ms
P3 2 ms 9 ms
P4 3 ms 5 ms
Execution Order (Gantt Chart Representation):
| P1 | P2 | P4 | P1 | P3 |
0 1 5 10 17 26
• Completion Time (CT):
o P1 = 17 ms
o P2 = 5 ms
o P3 = 26 ms
o P4 = 10 ms
• Turnaround Time (TAT) = Completion Time - Arrival Time
o P1 = 17 - 0 = 17 ms
o P2 = 5 - 1 = 4 ms
o P3 = 26 - 2 = 24 ms
o P4 = 10 - 3 = 7 ms
• Waiting Time (WT) = Turnaround Time - Burst Time
o P1 = 17 - 8 = 9 ms
o P2 = 4 - 4 = 0 ms
o P3 = 24 - 9 = 15 ms
o P4 = 7 - 5 = 2 ms
Average Waiting Time (AWT):
AWT=(9+0+15+2)/4=26/4=6.5ms
Implementation of SRTF Scheduling in C++
Conclusion
• SRTF minimizes waiting time better than SJF and FCFS.
• It can cause starvation for longer processes.
• More efficient for CPU-bound processes but has high overhead due to frequent
context switching.
EXPERIMENT 6
ROUND ROBIN SCHEDULING
Objective:
To understand and implement the Round Robin (RR) scheduling algorithm in an operating
system.
Introduction to Round Robin Scheduling
The Round Robin (RR) scheduling algorithm is a preemptive scheduling method designed
for time-sharing systems. It assigns a fixed time quantum to each process in a cyclic order.
Characteristics of Round Robin:
• Time quantum: A small, fixed time slice assigned to each process.
• Preemptive: If a process doesn’t complete within its time slice, it is moved to the end
of the queue.
• Fair allocation: All processes get equal CPU time, preventing starvation.
Advantages:
i. Prevents starvation by giving each process equal CPU time.
ii. Efficient for time-sharing and interactive systems.
iii. Low response time compared to FCFS and SJF.
Disadvantages:
i. Higher average waiting time if the time quantum is not optimal.
ii. More context switching, increasing overhead.
Example of Round Robin Scheduling
Given Processes:
Process Arrival Time Burst Time
P1 0 ms 5 ms
P2 1 ms 3 ms
P3 2 ms 8 ms
P4 3 ms 6 ms
Assuming Time Quantum = 3 ms
Execution Order (Gantt Chart Representation):
| P1 | P2 | P3 | P4 | P1 | P3 | P4 | P3 |
0 3 6 9 12 14 17 20 22
• Completion Time (CT):
o P1 = 14 ms
o P2 = 6 ms
o P3 = 22 ms
o P4 = 20 ms
• Turnaround Time (TAT) = Completion Time - Arrival Time
o P1 = 14 - 0 = 14 ms
o P2 = 6 - 1 = 5 ms
o P3 = 22 - 2 = 20 ms
o P4 = 20 - 3 = 17 ms
• Waiting Time (WT) = Turnaround Time - Burst Time
o P1 = 14 - 5 = 9 ms
o P2 = 5 - 3 = 2 ms
o P3 = 20 - 8 = 12 ms
o P4 = 17 - 6 = 11 ms
Average Waiting Time (AWT):
AWT=(9+2+12+11)/4=34/4=8.5 ms
Implementation of Round Robin Scheduling in C
Conclusion
• Round Robin ensures fair CPU time for all processes.
• Time quantum plays a crucial role in performance.
• Shorter time quantum leads to frequent context switches.
• Larger time quantum behaves like FCFS.
EXPERIMENT 7
NON-PREEMPTIVE PRIORITY SCHEDULING
Objective:
To understand and implement the Non-Preemptive Priority Scheduling algorithm in
an operating system.
Introduction to Non-Preemptive Priority Scheduling
The Priority Scheduling algorithm assigns a priority to each process, and the CPU
executes the process with the highest priority first.
Types of Priority Scheduling:
1. Preemptive – A higher-priority process can preempt a running process.
2. Non-Preemptive – The CPU executes the process until completion, even if a
higher-priority process arrives.
Characteristics of Non-Preemptive Priority Scheduling:
• Processes are executed based on priority, not arrival time.
• Higher priority = executed first (lower priority number is considered higher).
• If two processes have the same priority, FCFS (First Come, First Served) is
used.
Advantages:
i. Efficient for important tasks (e.g., real-time systems).
ii. Lower-priority processes do not interrupt high-priority tasks.
Disadvantages:
i. Starvation – Low-priority processes may never get executed.
ii. Not fair for all processes (unlike Round Robin).
Example of Non-Preemptive Priority Scheduling
Given Processes:
Process Arrival Time Burst Time Priority
P1 0 ms 8 ms 3
P2 1 ms 4 ms 1
P3 2 ms 9 ms 4
P4 3 ms 5 ms 2
Execution Order (Based on Priority)
| P2 | P4 | P1 | P3 |
1 5 10 18 27
• Completion Time (CT):
o P1 = 18 ms
o P2 = 5 ms
o P3 = 27 ms
o P4 = 10 ms
• Turnaround Time (TAT) = Completion Time - Arrival Time
o P1 = 18 - 0 = 18 ms
o P2 = 5 - 1 = 4 ms
o P3 = 27 - 2 = 25 ms
o P4 = 10 - 3 = 7 ms
• Waiting Time (WT) = Turnaround Time - Burst Time
o P1 = 18 - 8 = 10 ms
o P2 = 4 - 4 = 0 ms
o P3 = 25 - 9 = 16 ms
o P4 = 7 - 5 = 2 ms
Average Waiting Time (AWT):
AWT=(10+0+16+2)/4=28/4=7.0 ms
Implementation of Non-Preemptive Priority Scheduling in C++
Conclusion
• Non-preemptive priority scheduling ensures that high-priority processes execute first.
• Starvation may occur for low-priority processes.
• FCFS is used as a tiebreaker when processes have the same priority.
• Useful in real-time and critical systems where task prioritization is needed.
EXPERIMENT 8
PREEMPTIVE PRIORITY SCHEDULING
Objective:
To understand and implement the Preemptive Priority Scheduling algorithm in an operating
system.
Introduction to Preemptive Priority Scheduling
Preemptive Priority Scheduling is a CPU scheduling technique in which each process is
assigned a priority. The CPU is allocated to the process with the highest priority (lower
numerical value means higher priority). Unlike non-preemptive scheduling, the currently
running process can be interrupted if a new process with a higher priority arrives.
Characteristics of Preemptive Priority Scheduling:
• The CPU is assigned to the process with the highest priority.
• A running process can be preempted if a higher-priority process arrives.
• If two processes have the same priority, FCFS (First Come First Served) is used.
Advantages:
1. Ensures important tasks are completed early.
2. More responsive to real-time tasks.
Disadvantages:
1. Frequent context switching increases overhead.
2. Low-priority processes may suffer from starvation.
Example:
Process Arrival Time Burst Time Priority
P1 0 ms 8 ms 3
P2 1 ms 4 ms 1
P3 2 ms 9 ms 4
P4 3 ms 5 ms 2
Execution Order (Gantt Chart):
| P1 | P2 | P4 | P1 | P3 |
0 1 5 10 18 27
Completion Time (CT):
• P1 = 18 ms
• P2 = 5 ms
• P3 = 27 ms
• P4 = 10 ms
Turnaround Time (TAT) = Completion Time - Arrival Time
• P1 = 18 - 0 = 18 ms
• P2 = 5 - 1 = 4 ms
• P3 = 27 - 2 = 25 ms
• P4 = 10 - 3 = 7 ms
Waiting Time (WT) = Turnaround Time - Burst Time
• P1 = 18 - 8 = 10 ms
• P2 = 4 - 4 = 0 ms
• P3 = 25 - 9 = 16 ms
• P4 = 7 - 5 = 2 ms
Average Waiting Time (AWT):
AWT = (10 + 0 + 16 + 2) / 4 = 7.0 ms
Implementation of Preemptive Priority Scheduling in C++
Conclusion:
• Preemptive Priority Scheduling gives higher priority processes more importance.
• Improves responsiveness in systems with real-time or critical tasks.
• FCFS is used when multiple processes have the same priority.
• Starvation can occur for lower priority processes.
• Ideal for dynamic systems with time-sensitive tasks.
EXPERIMENT 8
BANKER’S ALGORITHM
Objective:
To implement the Banker’s Algorithm for deadlock avoidance in operating systems.
Introduction to Banker’s Algorithm
The Banker’s Algorithm is a resource allocation and deadlock avoidance algorithm
developed by Edsger Dijkstra. It ensures that the system stays in a safe state by simulating
resource allocation for predetermined maximum needs and checking the possibility of all
processes completing.
Key Concepts:
• Available[]: Resources currently available.
• Max[][]: Maximum demand of each process.
• Allocation[][]: Resources currently allocated to each process.
• Need[][] = Max - Allocation: Remaining resource need of each process.
Working:
1. The system checks if resources can be allocated to a process such that it can complete.
2. If yes, resources are tentatively allocated.
3. The system verifies that after this allocation, all other processes can still finish.
4. If such a sequence exists, the system is in a safe state; otherwise, it’s unsafe.
Example:
Let there be 5 processes (P0–P4) and 3 resource types (A, B, C).
Available: A = 3, B = 3, C = 2
Allocation Matrix:
Process A B C
P0 0 1 0
P1 2 0 0
P2 3 0 2
P3 2 1 1
P4 0 0 2
Max Matrix:
Process A B C
P0 7 5 3
P1 3 2 2
P2 9 0 2
P3 2 2 2
P4 4 3 3
Need = Max - Allocation
Implementation of Banker’s Algorithm in C++
Conclusion:
• The Banker’s Algorithm helps prevent deadlock by ensuring safe resource allocation.
• It checks if granting resources keeps the system in a safe state.
• If no safe sequence is found, it denies the request, avoiding unsafe states.
• Best suited for systems where resource requests are predictable and limited.