DELHI TECHNOLOGICAL UNIVERSITY
DEPARTMENT OF COMPUTER SCIENCE AND
ENGINEERING
OS Experiment File
Submitted by:
Arsh Abbas Naqvi
24/CSE/099
Experiment - 1
Objective
Basic Linux commands
Answer:
1. pwd
Usage: Show current working directory
Syntax: pwd
2. ls
Usage: List files and directories
Syntax: ls [options] [directory]
3. cd
Usage: Change directory
Syntax: cd [directory]
4. mkdir
Usage: Create a new directory
Syntax: mkdir [directory_name]
5. rmdir
Usage: Remove an empty directory
Syntax: rmdir [directory_name]
6. touch
Usage: Create an empty file or update timestamp
Syntax: touch [file_name]
7. cp
Usage: Copy files or directories
Syntax: cp [options] source destination
8. mv
Usage: Move or rename files/directories
Syntax: mv [source] [destination]
9. rm
Usage: Remove files or directories
Syntax: rm [options] [file_name]
10. cat
Usage: Display contents of a file
Syntax: cat [file_name]
11. less
Usage: View file content one page at a time
Syntax: less [file_name]
12. head
Usage: Show first lines of a file
Syntax: head [options] [file_name]
13. tail
Usage: Show last lines of a file
Syntax: tail [options] [file_name]
14. grep
Usage: Search for patterns in files
Syntax: grep [pattern] [file_name]
15. find
Usage: Search for files/directories
Syntax: find [path] [options] [expression]
16. ps
Usage: Show running processes
Syntax: ps [options]
17. whoami
Usage: Display current user
Syntax: whoami
18. uptime
Usage: Show system uptime
Syntax: uptime
19. df
Usage: Show disk space usage
Syntax: df [options]
20. free
Usage: Show memory usage
Syntax: free [options]
21. chmod
Usage: Change file permissions
Syntax: chmod [permissions] [file_name]
22. chown
Usage: Change file ownership
Syntax: chown [owner][:group] [file_name]
23. echo
Usage: Print text to terminal
Syntax: echo [string]
24. clear
Usage: Clear the terminal screen
Syntax: clear
25. man
Usage: Show manual/help for a command
Syntax: man [command]
Experiment - 2
Objective
Types of OS
Answer
1. Batch Operating System
Usage: Executes batches of jobs without user interaction
Examples: Early IBM mainframe OS
2. Time-Sharing Operating System
Usage: Allows multiple users to share system resources simultaneously
Examples: UNIX, Multics
3. Distributed Operating System
Usage: Manages a group of independent computers as a single system
Examples: Amoeba, Plan 9
4. Network Operating System (NOS)
Usage: Provides networking features like file sharing, printer access, and
communication between computers
Examples: Windows Server, Novell NetWare
5. Real-Time Operating System (RTOS)
Usage: Ensures immediate processing and predictable response times; used in
critical systems
Examples: VxWorks, QNX, FreeRTOS
6. Multiprogramming Operating System
Usage: Runs multiple programs in memory at the same time to increase CPU
utilization
Examples: Early UNIX, IBM OS/360
7. Multi-User Operating System
Usage: Supports multiple users working on the same system at once
Examples: Linux, UNIX, Windows Server
8. Multitasking Operating System
Usage: Allows execution of multiple tasks (processes) at the same time
Examples: Windows, macOS, Linux
9. Mobile Operating System
Usage: Designed specifically for mobile devices with touch interfaces
Examples: Android, iOS, HarmonyOS
10. Embedded Operating System
Usage: Lightweight OS designed for embedded systems with limited
resources
Examples: Embedded Linux, Windows IoT, RTOS variants
Experiment 3
Objective
Write a program to show First Come First Serve Scheduling
Code
using namespace std;
#include <bits/stdc++.h>
class Process {
public:
int at; // arrival time
int bt; // burst time
int ct; // completion time
int tat; // turnaround time
int wt; // waiting time
int pid; // process id
void update_after_ct() {
tat = ct - at;
wt = tat - bt;
}
void display() {
printf("%d\t%d\t%d\t%d\t%d\t%d\n", pid, at, bt, ct, tat, wt);
}
};
bool compareArrival(const Process &first, const Process &second) {
return first.at < second.at;
}
float average(const vector<int> &nums) {
int total = 0;
for (size_t i = 0; i < nums.size(); i++) {
total += nums[i];
}
return (float)total / nums.size();
}
int main() {
int n;
printf("n\n");
cin >> n;
vector<Process> P(n);
printf("at bt\n");
for (int i = 0; i < n; i++) {
P[i].pid = i + 1; // assign process id
cin >> P[i].at >> P[i].bt;
}
sort(P.begin(), P.end(), compareArrival);
printf("pid\tat\tbt\tct\ttat\twt\n");
P[0].ct = P[0].at + P[0].bt;
P[0].update_after_ct();
P[0].display();
for (int i = 1; i < n; i++) {
if (P[i].at < P[i - 1].ct) {
P[i].ct = P[i - 1].ct + P[i].bt;
} else {
P[i].ct = P[i].at + P[i].bt;
}
P[i].update_after_ct();
P[i].display();
}
vector<int> waitingTimes, turnaroundTimes;
for (int i = 0; i < n; i++) {
waitingTimes.push_back(P[i].wt);
turnaroundTimes.push_back(P[i].tat);
}
printf("Average waiting time : %f\n", average(waitingTimes));
printf("Average turnaround time : %f\n", average(turnaroundTimes));
return 0;
}
Output
Experiment - 4
Objective
Write a program to show Shortest Job first scheduling
Code
using namespace std;
#include <bits/stdc++.h>
class Process {
public:
int at; // arrival time
int bt; // burst time
int ct; // completion time
int tat; // turnaround time
int wt; // waiting time
int pid; // process id
void update_after_ct() {
tat = ct - at;
wt = tat - bt;
}
void display() {
printf("%d\t%d\t%d\t%d\t%d\t%d\n", pid, at, bt, ct, tat, wt);
}
};
bool compareArrival(const Process &first, const Process &second) {
return first.at < second.at;
}
float average(const vector<int> &nums) {
int total = 0;
for (size_t i = 0; i < nums.size(); i++) {
total += nums[i];
}
return (float)total / nums.size();
}
int main() {
int n;
printf("n\n");
cin >> n;
vector<Process> P(n);
printf("at bt\n");
for (int i = 0; i < n; i++) {
P[i].pid = i + 1; // assign process id
cin >> P[i].at >> P[i].bt;
}
sort(P.begin(), P.end(), compareArrival);
printf("pid\tat\tbt\tct\ttat\twt\n");
int time = 0;
vector<bool> done(n, false);
int completed = 0;
while (completed < n) {
int idx = -1, minBT = INT_MAX;
for (int i = 0; i < n; i++) {
if (!done[i] && P[i].at <= time) {
if (P[i].bt < minBT) {
minBT = P[i].bt;
idx = i;
}
}
}
if (idx == -1) {
int nextArrival = INT_MAX;
for (int i = 0; i < n; i++) {
if (!done[i]) {
nextArrival = min(nextArrival, P[i].at);
}
}
time = nextArrival;
continue;
}
// run selected process
time += P[idx].bt;
P[idx].ct = time;
P[idx].update_after_ct();
P[idx].display();
done[idx] = true;
completed++;
}
vector<int> waitingTimes, turnaroundTimes;
for (int i = 0; i < n; i++) {
waitingTimes.push_back(P[i].wt);
turnaroundTimes.push_back(P[i].tat);
}
printf("Average waiting time : %f\n", average(waitingTimes));
printf("Average turnaround time : %f\n", average(turnaroundTimes));
return 0;
}
Output
Experiment - 5
Objective
Write a program to implement non preemptive priority scheduling
Code
// NON PREMPTIVE PRIORITY SCHEDULING
#include <bits/stdc++.h>
using namespace std;
class Process {
public:
int at; // arrival time
int bt; // burst time
int ct; // completion time
int tat; // turnaround time
int wt; // waiting time
int pid; // process id
int priority; //priority
void update_after_ct() {
tat = ct - at;
wt = tat - bt;
}
void display() {
printf("%d\t%d\t%d\t%d\t%d\t%d\t%d\n", pid, at, bt, ct, tat, wt,
priority);
}
};
float average(const vector<int> &nums) {
int total = 0;
for (size_t i = 0; i < nums.size(); i++) {
total += nums[i];
}
return (float)total / nums.size();
}
int main() {
int n;
printf("n\n");
cin >> n;
vector<Process> P(n);
printf("at bt priority\n");
for (int i = 0; i < n; i++) {
P[i].pid = i + 1;
cin >> P[i].at >> P[i].bt >> P[i].priority;
}
printf("pid\tat\tbt\tct\ttat\twt\tpriority\t\n");
P[0].ct = P[0].at + P[0].bt;
P[0].update_after_ct();
P[0].display();
int time = 0, completed = 0;
vector<bool> done(n, false);
while (completed < n) {
int idx = -1;
int bestPriority = INT_MAX; // set to lowest priority possible in
cpp
for (int i = 1; i < n; i++) {
if (!done[i] && P[i].at <= time) {
if (P[i].priority < bestPriority) {
bestPriority = P[i].priority;
idx = i;
}
}
}
if (idx == -1) {
time++;
} else {
P[idx].ct = time + P[idx].bt;
time = P[idx].ct;
P[idx].update_after_ct();
P[idx].display();
done[idx] = true;
completed++;
}
}
vector<int> waitingTimes, turnaroundTimes;
for (int i = 0; i < n; i++) {
waitingTimes.push_back(P[i].wt);
turnaroundTimes.push_back(P[i].tat);
}
printf("Average waiting time : %f\n", average(waitingTimes));
printf("Average turnaround time : %f\n", average(turnaroundTimes));
return 0;
}
Output
Experiment - 6
Objective
Write a program to implement round robin scheduling
Code
#include <bits/stdc++.h>
using namespace std;
class Process {
public:
int pid; // process id
int at; // arrival time
int bt; // burst time
int ct; // completion time
int tat; // turnaround time
int wt; // waiting time
int rt; // remaining time
};
int main() {
int n, tq;
cout << "Enter number of processes: ";
cin >> n;
cout << "Enter time quantum: ";
cin >> tq;
vector<Process> p(n);
for (int i = 0; i < n; i++) {
cout << "Enter arrival time and burst time for P" << i + 1 << ": ";
p[i].pid = i + 1;
cin >> p[i].at >> p[i].bt;
p[i].rt = p[i].bt;
}
queue<int> q; // ready queue
vector<bool> inQueue(n, false);
int time = 0, completed = 0;
float totalTAT = 0, totalWT = 0;
// initially push processes that arrive at time 0
for (int i = 0; i < n; i++) {
if (p[i].at == 0) {
q.push(i);
inQueue[i] = true;
}
}
while (completed < n) {
if (q.empty()) {
time++; // CPU idle
for (int i = 0; i < n; i++) {
if (!inQueue[i] && p[i].at <= time) {
q.push(i);
inQueue[i] = true;
}
}
continue;
}
int idx = q.front();
q.pop();
int execTime = min(tq, p[idx].rt);
p[idx].rt -= execTime;
time += execTime;
// check for new arrivals during this execution window
for (int i = 0; i < n; i++) {
if (!inQueue[i] && p[i].at <= time && p[i].rt > 0) {
q.push(i);
inQueue[i] = true;
}
}
if (p[idx].rt == 0) {
p[idx].ct = time;
p[idx].tat = p[idx].ct - p[idx].at;
p[idx].wt = p[idx].tat - p[idx].bt;
totalTAT += p[idx].tat;
totalWT += p[idx].wt;
completed++;
} else {
q.push(idx); // not finished → requeue
}
}
cout << "\nPID\tAT\tBT\tCT\tTAT\tWT\n";
for (auto &proc : p) {
cout << "P" << proc.pid << "\t" << proc.at << "\t" << proc.bt << "\t"
<< proc.ct << "\t" << proc.tat << "\t" << proc.wt << "\n";
}
cout << "\nAverage TAT = " << totalTAT / n;
cout << "\nAverage WT = " << totalWT / n << "\n";
return 0;
}
Output