Professional Documents
Culture Documents
UNIVERSITY
B.TECH – ICT Div 4 H8
Laboratory Manual
Name:SHIVANI ODEDRA
Roll no.: 21BIT267
Subject: Operating Systems Laboratory
Semester: 5
Submitted to
Shivangi
Mehta
Department of
Information and Communication Technology
Engineering
Certificat
e
rd
Exam No. of 3 Year B.TECH Degree in Information and
Technology, PDEU.
Date of Submission:
Signature:
2|Page
Operating Systems 21BIT267
Index
Page
Sr. s Date of
Experiment Title Marks Sign.
No Completion
.
F T
ro o
m
1 Linux Commands. 5 10
2 Shell Scripting 11 1
4
3 To write program to 15 2
perform FCFS and SJF 4
scheduling algorithms.
4 To write program to perform 25 3
Priority and Round-Robbin 5
scheduling algorithms.
3|Page
Operating Systems 21BIT267
4|Page
Operating Systems 21BIT267
Experiment-1
Practicality
5|Page
Operating Systems 21BIT267
Linux Commands.
Linux Commands.
1) pwd- shows your
current location
2) mkdir- creates a
new, empty directory
whose name is defined by
path.
6|Page
Operating Systems 21BIT267
3) rmdir-
removes
the
4) ls- used
to list
files.
5)
7|Page
Operating Systems 21BIT267
cd- used to change the working directory of the working drive or another
lettered drive.
6) touch- used to update the access date and/or modification date of
a computer file or directory.
8|Page
Operating Systems 21BIT267
8) rm- removes the entries for a specified file, group of files, or certain select
9) cp-
used to
copy
files or
groups
of files
or
directories.
10) mv- used to move files and directories from one directory to another or to
9|Page
Operating Systems 21BIT267
11) head- allows you to see the initial lines of a file in standard
12) tail- prints data from the end of a specified file or files to standard output.
10 | P a g e
Operating Systems 21BIT267
11 | P a g e
Operating Systems 21BIT267
15) wc- used to find out number of lines, word count, byte and
characters count in the files specified in the file arguments.
12 | P a g e
Operating Systems 21BIT267
Theory program will be saved using .sh extension echo is printf of shell scripting. read is
scanf of shell scripting.
Given that: Write a script called which outputs the following:
· Your username.
· The time and date.
· Who is logged on.
· Also output a line of asterisks after every execution.
· Touch command used to make a new file.
· chmod is a command gives the permission of read, write or execute.
· chmod +rwx filename.sh
13 | P a g e
Operating Systems 21BIT267
14 | P a g e
Operating Systems 21BIT267
15 | P a g e
Operating Systems 21BIT267
16 | P a g e
Operating Systems 21BIT267
Experiment-3
Aim: To write program to perform FCFS and SJF scheduling algorithms.
FCFS:
Code:
#include <stdio.h>
struct Process
{
int pid; // Process ID
int arrivalTime; // Arrival Time
int burstTime; // Burst Time
int startTime; // Start Time
int endTime; // End Time
int turnaroundTime; // Turnaround
Time int waitingTime; // Waiting
Time
};
17 | P a g e
Operating Systems 21BIT267
18 | P a g e
Operating Systems 21BIT267
{
printf("%d\t%d\t\t%d\t\t%d\t\t%d\t\t%d\n",
processes[i].pid, processes[i].arrivalTime, processes[i].burstTime,
processes[i].endTime, processes[i].turnaroundTime, processes[i].waitingTime);
avgTurnaroundTime +=
processes[i].turnaroundTime; avgWaitingTime +=
processes[i].waitingTime;
}
avgTurnaroundTime /=
n; avgWaitingTime /= n;
int main()
{
int n;
printf("Enter the number of processes: ");
scanf("%d", &n);
sortProcessesByArrivalTime(processes, n);
calculateTimes(processes, n); displayResults(processes, n);
return 0;
}
Output:
2) SJF:
Code:
#include <stdio.h>
#include <stdbool.h>
struct Process
{
int id;
21 | P a g e
Operating Systems 21BIT267
int arrivalTime;
int burstTime;
int completionTime;
}
22 | P a g e
Operating Systems 21BIT267
if (shortestIndex == -1)
{
currentTime++;
i--;
}
else
{
processes[shortestIndex].completionTime = currentTime +
processes[shortestIndex].burstTime;
processes[shortestIndex].turnaroundTime = processes[shortestIndex].completionTime
- processes[shortestIndex].arrivalTime;
processes[shortestIndex].waitingTime = processes[shortestIndex].turnaroundTime -
processes[shortestIndex].burstTime;
currentTime = processes[shortestIndex].completionTime;
totalWaitingTime += processes[shortestIndex].waitingTime;
totalTurnaroundTime +=
processes[shortestIndex].turnaroundTime;
}
}
processes[i].turnaroundTime,
processes[i].waitingTime);
23 | P a g e
Operating Systems 21BIT267
{
int currentTime = 0;
int totalWaitingTime = 0;
int totalTurnaroundTime = 0;
int completedProcesses = 0;
24 | P a g e
Operating Systems 21BIT267
shortestBurstTime = processes[i].remainingTime;
}
}
}
if (shortestIndex == -1)
{
currentTime++;
}
ELSE
{
processes[shortestIndex].remainingTime--;
currentTime++;
if (processes[shortestIndex].remainingTime == 0)
{
processes[shortestIndex].completionTime = currentTime;
processes[shortestIndex].turnaroundTime =
processes[shortestIndex].completionTime - processes[shortestIndex].arrivalTime;
processes[shortestIndex].waitingTime = processes[shortestIndex].turnaroundTime -
processes[shortestIndex].burstTime;
totalWaitingTime += processes[shortestIndex].waitingTime;
totalTurnaroundTime +=
processes[shortestIndex].turnaroundTime; completedProcesses++;
}
}
}
printf("Preemptive SJF Scheduling:\n");
25 | P a g e
Operating Systems 21BIT267
processes[i].turnaroundTime,
processes[i].waitingTime);
}
printf("Average Turnaround Time: %.2f\n", (float)totalTurnaroundTime /
n); printf("Average Waiting Time: %.2f\n", (float)totalWaitingTime / n);
}
int main()
{
int n;
printf("Enter the number of processes: ");
scanf("%d", &n);
int choice;
printf("Select scheduling type:\n");
printf("1. Non-preemptive SJF\n");
printf("2. Preemptive SJF\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice)
{
case 1:
nonPreemptiveSJF(processes, n);
break;
case 2:
preemptiveSJF(processes,
n); break;
default:
printf("Invalid choice!\n");
break;
}
return 0;
}
27 | P a g e
Operating Systems 21BIT267
Output:
EXPERIMENT - 4
AIM: To write program to perform Priority and Round-Robbin scheduling
algorithms.
CODE:
PRIORITY CODE:
#include <iostream>
#include <algorithm>
using namespace std;
struct Process
{
int pid; // Process ID
int at; // Arrival time
int bt; // CPU Burst time required
int priority; // Priority of this process
int ct; // Completion time
int wt; // Waiting time
int tat; // Turnaround
time
int remaining_bt; // Remaining burst time
};
28 | P a g e
Operating Systems 21BIT267
if (b.at == 0)
return false;
return (a.priority > b.priority);
}
29 | P a g e
Operating Systems 21BIT267
total_wt += proc[i].wt;
total_tat += proc[i].tat;
}
if (selectedProcess == -1)
31 | P a g e
Operating Systems 21BIT267
{
currentTime++;
}
else
{
proc[selectedProcess].remaining_bt--;
currentTime++;
if (proc[selectedProcess].remaining_bt == 0)
{
completedProcesses[selectedProcess] = 1;
completed++;
proc[selectedProcess].ct = currentTime;
proc[selectedProcess].tat = proc[selectedProcess].ct - proc[selectedProcess].at;
proc[selectedProcess].wt = proc[selectedProcess].tat - proc[selectedProcess].bt;
}
}
}
proc[i].tat;
cout << " " << proc[i].pid << "\t\t" << proc[i].at << "\t\t"
<< proc[i].bt << "\t " << proc[i].priority << "\t\t" << proc[i].ct
<< "\t\t " << proc[i].wt << "\t\t " << proc[i].tat << endl;
}
int main()
{
int n;
cout << "Enter the number of processes: ";
cin >> n;
Process proc[n];
for (int i = 0; i < n; i++)
{
cout << "Enter Process " << i + 1 << " details (at bt priority): ";
cin >> proc[i].at >> proc[i].bt >> proc[i].priority;
33 | P a g e
Operating Systems 21BIT267
int choice;
cout << "\nSelect Scheduling Method:\n";
switch (choice)
{
case 1:
nonPreemptivePriorityScheduling(proc,
n); break;
case 2:
preemptivePriorityScheduling(proc, n);
break;
default:
cout << "Invalid choice!";
}
34 | P a g e
Operating Systems 21BIT267
return 0;
}
Output:
1) Non- preemptive:
35 | P a g e
Operating Systems 21BIT267
2) Preemptive:
#include <iostream>
void queueUpdation(int queue[], int timer, int arrival[], int n, int maxProccessIndex)
{
int zeroIndex;
for (int i = 0; i < n; i++)
{
if (queue[i] == 0)
{
zeroIndex = i;
break;
}
}
queue[zeroIndex] = maxProccessIndex + 1;
}
36 | P a g e
Operating Systems 21BIT267
void checkNewArrival(int timer, int arrival[], int n, int maxProccessIndex, int queue[])
{
if (timer <= arrival[n - 1])
{
bool newArrival = false;
for (int j = (maxProccessIndex + 1); j < n; j++)
{
if (arrival[j] <= timer)
{
if (maxProccessIndex < j)
{
maxProccessIndex = j;
newArrival = true;
}
}
}
if (newArrival)
queueUpdation(queue, timer, arrival, n, maxProccessIndex);
}
}
int main()
{
int n, tq, timer = 0, maxProccessIndex = 0;
float avgWait = 0, avgTT = 0;
cout << "\nEnter the time quanta : ";
cin >> tq;
cout << "\nEnter the number of processes : ";
cin >> n;
int arrival[n], burst[n], wait[n], turn[n], queue[n], temp_burst[n];
bool complete[n];
37 | P a g e
Operating Systems 21BIT267
false; queue[i] = 0;
}
while (timer < arrival[0])
timer++;
queue[0] = 1;
while (true)
{
bool flag = true;
for (int i = 0; i < n; i++)
{
if (temp_burst[i] != 0)
{
flag = false;
break;
}
}
if (flag)
break;
38 | P a g e
Operating Systems 21BIT267
}
}
else
idle = false;
if (idle)
{
timer++;
checkNewArrival(timer, arrival, n, maxProccessIndex, queue);
}
queueMaintainence(queue, n);
}
}
return 0;
}
Output:
39 | P a g e
Operating Systems 21BIT267
40 | P a g e