DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING
[Link] — Semester IV
PRACTICAL FILE
BTCS404-18
Operating Systems Lab
Name: ________________________________
Roll Number: ________________________________
Section / Group: ________________________________
Faculty: ________________________________
Academic Year: 2025 – 26
INDEX
Sr. No. Experiment / Task Name Page No.
1 Task 1: Installation Process of Various Operating Systems 3
2 Task 2: CPU Scheduling Algorithms (FCFS, SJF, Round Robin, 5
Priority)
3 Task 3: Virtualization & Virtual Machine Installation 11
4 Task 4: Linux File, Directory & Process Commands 14
5 Task 5: Shell Programming in Bash 18
6 Task 6: Banker's Algorithm for Deadlock Avoidance 23
TASK 1
Installation Process of Various Operating Systems
Experiment No. 1
Date
Title Installation Process of Various Operating Systems
To understand and demonstrate the step-by-step installation
Objective process of different operating systems including Windows and
Linux distributions.
Theory
An operating system (OS) is the backbone software that manages computer hardware and software
resources. Installing an OS is one of the first practical skills in system administration. The process varies
slightly between Windows-based and Unix/Linux-based systems, but the core concepts remain the
same.
The installation process typically involves three phases: pre-installation (BIOS/UEFI setup, bootable
media), the installation wizard, and post-installation configuration (drivers, updates, software).
Tools / Requirements
• A PC with at least 4 GB RAM and 50 GB free disk space
• Bootable USB drive (8 GB or higher)
• Windows 10/11 ISO or Ubuntu/Kali Linux ISO
• Rufus or Etcher (to create bootable USB)
• A working internet connection (for driver downloads)
Procedure — Windows 10 Installation
1. Download the Windows 10 ISO from the Microsoft website.
2. Use Rufus to write the ISO onto the USB drive (Partition Scheme: GPT for UEFI).
3. Plug in the USB, restart the PC, and press F12 / Del to enter BIOS. Set USB as primary boot
device.
4. The Windows Setup screen will appear. Select Language, Time, and Keyboard layout, then click
"Install Now".
5. Accept the license agreement. Choose "Custom Install" for a fresh setup.
6. Delete existing partitions (if any) or create new ones. Allocate at least 40 GB to the system drive.
7. The installer copies files, installs features, and reboots several times — this takes around 20–30
minutes.
8. Set up your user account, choose privacy settings, and let Windows complete setup.
Procedure — Ubuntu Linux Installation
9. Download Ubuntu 22.04 LTS ISO from [Link] and flash it to USB using Etcher.
10. Boot from USB, select "Try or Install Ubuntu".
11. Choose installation type — "Normal Installation" with third-party drivers checked.
12. For dual boot, select "Install alongside Windows". Let the installer manage partition sizes.
13. Set your timezone, create a user account with a strong password, and click Install.
14. After installation, restart the PC and remove the USB drive when prompted.
15. On first boot, update the system: sudo apt update && sudo apt upgrade -y
Observation
Windows installation is largely GUI-driven and straightforward but requires activation and driver
installation separately. Linux (Ubuntu) installation is faster and includes most drivers out-of-the-box via
the open-source kernel. The dual-boot setup allows both OSes to coexist on the same machine using
GRUB bootloader.
Conclusion
The experiment helped us understand the complete lifecycle of OS installation — from creating bootable
media to first login. We observed that Linux gives more control during installation while Windows
prioritizes ease of use. Both OSes have their use cases in real-world scenarios.
TASK 2
CPU Scheduling Algorithms
Experiment No. 2
Date
CPU Scheduling Algorithms — FCFS, SJF, Round Robin,
Title
Priority
To implement and compare CPU scheduling algorithms and
Objective calculate turnaround time (TAT) and waiting time (WT) for
each.
Theory
The CPU scheduler selects a process from the ready queue and allocates the CPU to it. Different
algorithms prioritize different properties like fairness, throughput, or response time. The key metrics we
measure are:
• Turnaround Time (TAT) = Completion Time - Arrival Time
• Waiting Time (WT) = Turnaround Time - Burst Time
• Average TAT = Sum of all TATs / Number of Processes
a) First Come First Served (FCFS)
Processes are scheduled in the order they arrive. It's the simplest algorithm, non-preemptive, and suffers
from the "convoy effect" where short processes get stuck behind long ones.
Process Table — FCFS
Process Arrival Burst Completion TAT WT
P1 0 4 4 4 0
P2 1 3 7 6 3
P3 2 4 11 9 5
P4 3 3 14 11 8
Average Waiting Time = (0+3+5+8)/4 = 4.0 ms | Average TAT = (4+6+9+11)/4 = 7.5 ms
b) Shortest Job First (SJF)
SJF selects the process with the smallest burst time from the ready queue. This is optimal in terms of
average waiting time but can cause "starvation" for longer processes. We demonstrate the non-
preemptive version here.
Process Table — SJF
Process Arrival Burst Completion TAT WT
P1 0 3 3 3 0
P3 1 3 6 5 2
P2 2 5 11 9 4
P4 3 5 16 13 8
Average Waiting Time = (0+4+2+8)/4 = 3.5 ms | Average TAT = (3+9+5+13)/4 = 7.5 ms
c) Round Robin (Pre-emptive) — Time Quantum = 2
Each process gets a fixed time slice (quantum). After using its quantum, it is moved to the back of the
queue. This ensures fairness and good response time, making it ideal for time-sharing systems.
Process Table — Round Robin
Process Arrival Burst Completion TAT WT
P1 0 4 10 10 6
P2 1 3 12 11 8
P3 2 4 13 11 7
P4 3 3 14 11 8
Average WT = (6+8+7+8)/4 = 7.25 ms — Higher than SJF but fairer to all processes.
d) Priority Scheduling
Each process is assigned a priority number. The CPU is given to the process with the highest priority
(lower number = higher priority in many implementations). It can be preemptive or non-preemptive. Major
drawback: starvation of low-priority processes — solved using aging.
Process Arrival Burst Priority Completion TAT WT
P1 0 4 2 4 4 0
P2 1 3 1 7 6 3
P3 2 4 4 15 13 9
P4 3 3 3 10 7 4
Conclusion
Among all four algorithms, SJF gives the minimum average waiting time but is difficult to implement
practically since burst time is not always known in advance. Round Robin is the most fair and is widely
used in modern operating systems. Priority scheduling is useful in real-time systems where certain tasks
need precedence.
TASK 3
Virtualization & Virtual Machine Installation
Experiment No. 3
Date
Virtualization: Installation of Virtual Machine Software and OS
Title
on VM
To understand virtualization, install VirtualBox/VMware, and set
Objective
up a guest operating system on a virtual machine.
Theory
Virtualization is the technology that lets a single physical machine (host) run multiple operating systems
(guests) simultaneously, each isolated from the others. This is achieved through a software layer called
a Hypervisor.
There are two types of hypervisors:
• Type 1 (Bare-metal): Runs directly on hardware — e.g., VMware ESXi, Hyper-V
• Type 2 (Hosted): Runs on top of a host OS — e.g., VirtualBox, VMware Workstation
For this experiment, we use Oracle VirtualBox (Type 2) as it is free, cross-platform, and beginner-
friendly.
Benefits of Virtualization
• Run multiple OSes without rebooting the host machine
• Safe sandbox for testing software — crashes don't affect the host
• Easy snapshots to revert to a previous machine state
• Used extensively in cloud infrastructure (AWS, Azure, GCP)
Procedure
16. Download VirtualBox from [Link] and install it on the host machine.
17. Download an OS ISO — e.g., Ubuntu 22.04 LTS.
18. Open VirtualBox and click "New". Enter VM name (e.g., Ubuntu-Test), type: Linux, version:
Ubuntu 64-bit.
19. Allocate RAM — at least 2 GB recommended (4 GB for smooth experience).
20. Create a Virtual Hard Disk — VDI format, Dynamically Allocated, 20 GB minimum.
21. Go to Settings > Storage > Insert the ISO file under the optical drive (Controller: IDE).
22. Go to Settings > Network > Adapter 1 > Bridged Adapter for internet access in the VM.
23. Start the VM. It boots from the ISO. Follow the Ubuntu installation steps (similar to Task 1).
24. After installation, install Guest Additions from Devices menu for better screen resolution and
clipboard sharing.
25. Take a Snapshot of the clean install via Machine > Take Snapshot. This allows rollback anytime.
Key VirtualBox Settings
Setting Recommended Value
Base Memory 2048 MB (2 GB) minimum
Video Memory 128 MB — enable 3D Acceleration
Storage 20 GB dynamic VDI file
Network Bridged Adapter (for internet access)
Shared Clipboard Bidirectional (Devices > Shared Clipboard)
CPU Cores 2 vCPUs — improves VM performance
Observation
The guest OS (Ubuntu) ran inside a window on the Windows host machine. We could switch between
the host and guest using Ctrl+Alt. The VM was completely isolated — formatting the virtual disk did not
affect the host at all. The snapshot feature saved us during a failed package installation.
Conclusion
Virtualization is an essential concept in modern computing. VirtualBox provides an easy way to
experience multiple OS environments without needing extra hardware. This skill is highly relevant for
system administration, DevOps, and cloud computing careers.
TASK 4
Linux File, Directory & Process Commands
Experiment No. 4
Date
Linux Commands for Files, Directories, Processes, and Disk
Title
Management
To practice essential Linux commands for file handling,
Objective process management, disk inspection, and inter-process
communication.
Theory
Linux uses a unified file system hierarchy starting from the root directory "/". Everything in Linux —
including hardware devices — is treated as a file. The command-line interface (CLI) gives users direct
control over the OS and is far more powerful than a GUI for scripting and automation.
A. File & Directory Commands
Command Syntax / Example Description
ls -la ls -la /home List all files with permissions
cd cd /var/log Change directory
cp cp [Link] /tmp/ Copy files
mv mv [Link] [Link] Move or rename files
rm -rf rm -rf /tmp/test/ Delete files/directories
mkdir -p mkdir -p a/b/c Create nested directories
rmdir rmdir emptydir Remove empty directory
cat cat /etc/hosts View file contents
diff diff file1 file2 Compare two files line by line
df -h df -h Show disk free space (human-
readable)
du -sh du -sh /home/* Disk usage per directory
B. Process Management Commands
Processes in Linux can be managed, inspected, and controlled from the terminal. Each process has a
unique PID (Process ID).
ps aux # list all running processes
ps aux | grep firefox # search for specific process
kill -9 1234 # forcefully kill process with PID 1234
nice -n 10 ./[Link] # run script at lower priority (nice value 10)
renice -n -5 -p 1234 # change priority of running process
jobs # list background/suspended jobs
bg %1 # resume job 1 in background
fg %1 # bring job 1 to foreground
sleep 5 & # run sleep command in background
who # show logged-in users
C. Pipes and Filters
The pipe "|" operator connects the output of one command to the input of the next. This is one of Linux's
most powerful features.
ls -la | grep ".sh" # list only .sh files
cat /etc/passwd | wc -l # count lines in passwd file
ps aux | sort -k3 -rn | head -5 # top 5 CPU-hungry processes
cat [Link] | grep "ERROR" | sort | uniq -c # count unique errors
D. Text Processing Commands
Command Example Output/Purpose
grep grep -i "root" /etc/passwd Search pattern (case-insensitive)
find find / -name "*.log" -mtime -7 Find files modified in last 7 days
sort sort -n [Link] Sort file numerically
cut cut -d: -f1 /etc/passwd Extract first field (username)
wc wc -l [Link] Count lines in file
cal cal 2025 Display calendar for 2025
touch touch [Link] Create empty file / update timestamp
file file /bin/bash Determine file type
Conclusion
Linux commands provide granular control over the OS. The combination of pipes, filters, and text-
processing tools makes Linux incredibly powerful for automation and system administration. We noticed
how chaining commands with pipes gives results that would require GUI clicks across multiple menus in
Windows.
TASK 5
Shell Programming in Bash
Experiment No. 5
Date
Shell Programming: Bash Scripts, Loops, Conditionals, and
Title
Automation
To write and execute bash shell scripts using variables,
Objective conditionals, loops, case statements, functions, and command-
line arguments.
Theory
A shell is a command interpreter — the interface between the user and the OS kernel. Bash (Bourne
Again SHell) is the most popular shell in Linux. Shell scripts are plain text files containing a sequence of
commands, executed top-to-bottom by the shell interpreter.
Shell scripts are used for automation: backups, log rotation, batch processing, system monitoring, report
generation, and more. They save hours of manual repetitive work.
Script 1: Hello World & Variables
#!/bin/bash
# Script to demonstrate variables and basic I/O
NAME="Alok"
COURSE="Operating Systems Lab"
echo "Hello, $NAME!"
echo "Welcome to $COURSE"
echo "Today is: $(date +'%d %B %Y')"
echo "Current directory: $PWD"
Output:
Hello, Alok!
Welcome to Operating Systems Lab
Today is: 15 March 2025
Current directory: /home/student/scripts
Script 2: Conditional Statements (if-elif-else)
#!/bin/bash
# Grade checker using if-elif-else
echo -n "Enter your marks (out of 100): "
read marks
if [ $marks -ge 90 ]; then
echo "Grade: A+ — Excellent!"
elif [ $marks -ge 75 ]; then
echo "Grade: A — Very Good"
elif [ $marks -ge 60 ]; then
echo "Grade: B — Good"
elif [ $marks -ge 45 ]; then
echo "Grade: C — Average"
else
echo "Grade: F — Failed. Please try again."
fi
Script 3: Looping Statements
for loop — Print multiplication table:
#!/bin/bash
echo -n "Enter a number: "
read n
for i in $(seq 1 10); do
echo "$n x $i = $((n * i))"
done
while loop — Countdown timer:
#!/bin/bash
count=10
while [ $count -gt 0 ]; do
echo "T-minus $count..."
count=$((count - 1))
sleep 1
done
echo "Liftoff!"
Script 4: case Statement — Simple Menu
#!/bin/bash
echo "========== MENU =========="
echo "1. Show Date"
echo "2. Show Disk Usage"
echo "3. Show Logged-in Users"
echo "4. Exit"
echo -n "Enter choice: "
read choice
case $choice in
1) date ;;
2) df -h ;;
3) who ;;
4) echo "Goodbye!"; exit 0 ;;
*) echo "Invalid choice!" ;;
esac
Script 5: Functions & Arguments
#!/bin/bash
# Function to calculate factorial
factorial() {
local n=$1
if [ $n -le 1 ]; then
echo 1
else
local prev=$(factorial $((n-1)))
echo $((n * prev))
fi
}
echo -n "Enter a number: "
read num
result=$(factorial $num)
echo "Factorial of $num = $result"
Script 6: Automated Backup Script
This is a real-world utility script that backs up a directory with a timestamp in the filename.
#!/bin/bash
# Auto Backup Script
SOURCE="/home/student/documents"
DEST="/backup"
DATE=$(date +%Y%m%d_%H%M%S)
FILENAME="backup_$[Link]"
mkdir -p $DEST
tar -czf "$DEST/$FILENAME" "$SOURCE"
if [ $? -eq 0 ]; then
echo "Backup successful: $FILENAME"
echo "Size: $(du -sh $DEST/$FILENAME | cut -f1)"
else
echo "Backup FAILED!"
fi
Conclusion
Shell scripting is one of the most practical skills in Linux administration. We learned how variables,
conditionals, loops, case statements, and functions work together to build useful automation scripts. The
backup script demonstrated how these concepts apply in real-world system administration tasks.
TASK 6
Banker's Algorithm for Deadlock Avoidance
Experiment No. 6
Date
Title Banker's Algorithm for Deadlock Avoidance
To implement Dijkstra's Banker's Algorithm to determine
Objective whether a system is in a safe state and to find the safe
sequence of process execution.
Theory
The Banker's Algorithm, proposed by Edsger Dijkstra, is a deadlock avoidance algorithm used in
operating systems. It gets its name from the analogy of a bank that manages limited resources (money)
and only grants loans if it can ensure all clients will eventually be able to repay.
The algorithm works with three key data structures:
• Allocation Matrix — Resources currently held by each process
• Maximum Matrix — Maximum resources a process may ever request
• Need Matrix — Remaining resources needed (Need = Max - Allocation)
• Available Vector — Currently free resources in the system
Safe State Condition
A state is safe if there exists at least one Safe Sequence — an ordering of all processes such that each
process can complete using currently available resources plus resources released by processes that
finish before it.
Problem Statement
System has 3 resource types: A (10 units), B (5 units), C (7 units). Currently allocated and available
resources are:
Available Vector (after current allocations): A=3, B=3, C=2
Algorithm Steps (Safety Check)
26. Step 1: Initialize Work = Available = [3, 3, 2]. Finish[i] = false for all processes.
27. Step 2: Find process Pi such that Finish[i] = false AND Need[i] <= Work.
28. Step 3: Allocate: Work = Work + Allocation[i]. Set Finish[i] = true.
29. Step 4: Repeat step 2-3. If all Finish[i] = true, system is SAFE.
Execution Trace
Step Process Work Before Work After Reason
1 P1 [3,3,2] [5,3,2] Need[P1]=[1,2,2] <= Work
2 P3 [5,3,2] [7,4,3] Need[P3]=[6,0,0] <= Work
3 P4 [7,4,3] [7,4,5] Need[P4]=[0,1,1] <= Work
4 P2 [7,4,5] [10,4,7] Need[P2]=[7,4,3] <= Work
5 P0 [10,4,7] [10,5,7] Need[P0]=[7,4,3] <= Work
Safe Sequence Found: P1 → P3 → P4 → P2 → P0
Since all Finish[i] = true, the system is in a SAFE STATE. No deadlock will occur if processes are
executed in the above sequence.
C Implementation (Core Logic)
#include <stdio.h>
#define P 5
#define R 3
int main() {
int alloc[P][R] = {{0,1,0},{2,0,0},{3,0,2},{2,1,1},{0,0,2}};
int max[P][R] = {{7,5,3},{3,2,2},{9,0,2},{2,2,2},{4,3,3}};
int avail[R] = {3, 3, 2};
int need[P][R], finish[P]={0}, safe[P], work[R];
for(int i=0;i<P;i++)
for(int j=0;j<R;j++)
need[i][j] = max[i][j] - alloc[i][j];
for(int j=0;j<R;j++) work[j]=avail[j];
int count=0;
while(count < P) {
int found=0;
for(int i=0;i<P;i++) {
if(!finish[i]) {
int ok=1;
for(int j=0;j<R;j++)
if(need[i][j]>work[j]) { ok=0; break; }
if(ok) {
for(int j=0;j<R;j++) work[j]+=alloc[i][j];
safe[count++]=i; finish[i]=1; found=1;
}
}
}
if(!found) { printf("UNSAFE STATE!\n"); return 1; }
}
printf("Safe Sequence: ");
for(int i=0;i<P;i++) printf("P%d ", safe[i]);
return 0;
}
Output
Safe Sequence: P1 P3 P4 P2 P0
Conclusion
The Banker's Algorithm successfully identified a safe sequence, confirming the system is not in a
deadlock state. This algorithm is practically used in resource management systems where processes
declare their maximum needs upfront. While effective, it has limitations — it requires advance knowledge
of maximum resource needs, and processes must be finite. Despite this, it remains a foundational
concept in OS deadlock management.
— End of Practical File —
BTCS404-18 | Operating Systems Lab | 2 Credits