OS Lab File
OS Lab File
8 of 2013)
LABORATORY RECORD
Programme : UG
Specialization : Data Science & Artificial Intelligence
Semester & Year : IV & II
Name of Student : Kumud hasija
Registration. No : 11022210056
Section :E
Course Code : 21CS2114
Course Title : Operating System
Name of Teachers : Mr. Sahil Sehrawat
BONAFIDE CERTIFICATE
Reg. No : 11022210056
Certified that this is the BonafIde record of practical done as a part of Semester
IV during the academic year 2023 - 2024.
8 31-35
9 36-41
10 42-45
11 46-50
12 51-55
First Come First Serve scheduling
#include <stdio.h>
*a = *b;
*b = temp;
ct[0] = bt[0];
}
// Function to calculate waiting time
wt[0] = 0;
float avgwt = 0;
avgwt += wt[i]; }
float avgtat = 0;
avgtat += tat[i]; }
int main() {
int num;
scanf("%d", &num);
p[i] = i + 1;
scanf("%d", &at[i]);
scanf("%d", &bt[i]);
printf("\n"); }
arrivalTime(bt, at, p, num);
return 0;
}
Output
Process ID Arrival Time Burst Time Completion Time Waiting Time Turnaround Time
P3 0 3 3 0 3
P1 3 4 7 3 4
P5 4 3 10 7 6
P2 5 3 13 10 8
P4 5 1 14 13 9
#include <stdio.h>
*a = *b;
*b = temp;
ct[0] = bt[0];
}
// Function to calculate waiting time
wt[0] = 0;
float avgwt = 0;
avgwt += wt[i];
float avgtat = 0;
avgtat += tat[i];
int main()
int num;
scanf("%d", &num);
p[i] = i + 1;
scanf("%d", &at[i]);
scanf("%d", &bt[i]);
printf("\n");
return 0;
}
Output
Process ID Arrival Time Burst Time Completion Time Waiting Time Turnaround Time
P2 1 4 4 0 3
P1 0 9 13 4 13
P3 2 9 22 13 20
#include <stdio.h>
*a = *b;
*b = temp;
void priorityScheduling(int bt[], int at[], int p[], int priority[], int num) {
ct[0] = bt[0];
}
// Function to calculate waiting time
wt[0] = 0;
float avgwt = 0;
avgwt += wt[i];
float avgtat = 0;
avgtat += tat[i];
int main() {
int num;
scanf("%d", &num);
p[i] = i + 1;
scanf("%d", &at[i]);
scanf("%d", &bt[i]);
scanf("%d", &priority[i]);
printf("\n");
return 0;
}
Output
Enter number of processes: 5
Process ID Arrival Time Burst Time Priority Completion Time Waiting Time Turnaround Time
P1 0 3 3 3 0 3
P2 1 6 4 9 3 8
P4 2 2 7 11 9 9
P5 4 4 8 15 11 11
P3 3 1 9 16 15 13
#include<stdio.h>
void main()
scanf("%d", &NOP);
y = NOP;
scanf("%d", &at[i]);
scanf("%d", &bt[i]);
temp[i] = bt[i];
scanf("%d", &quant);
printf("\n Process No \t\t Burst Time \t\t TAT \t\t Waiting Time ");
for(sum=0, i = 0; y!=0; )
temp[i] = 0;
count=1;
y--;
wt = wt+sum-at[i]-bt[i];
tat = tat+sum-at[i];
count =0;
if(i==NOP-1)
i=0;
else if(at[i+1]<=sum)
i++;
else
i=0;
avg_wt = wt * 1.0/NOP;
}
Output
Enter total number of process : 5
P3 1 3 2
P4 2 4 2
P2 3 11 8
P5 3 9 6
P1 5 14 9
#include <stdbool.h>
int main()
int buffer_size;
int pageQueue[20];
int numPages;
int pageFaults = 0;
scanf("%d", &numPages);
scanf("%d",&buffer_size);
int frame[buffer_size];
scanf("%d", &pageQueue[i]);
}
for (int i = 0; i < buffer_size; i++) {
frame[i] = -1;
if (frame[j] == pageQueue[i]) {
pageFault = false;
break;
if (pageFault) {
frame[rear] = pageQueue[i];
pageFaults++;
return 0;
}
Output
Enter the number of pages: 14
#include <stdio.h>
#include <stdbool.h>
int findOpticalPage(int frame[], int pages[], int start, int numPages, int numFrames) {
int j;
if (frame[i] == pages[j]) {
if (j > farthest) {
farthest = j;
optIndex = i;
break;
if (j == numPages) {
return i;
if (j == numPages) {
optIndex = i;
break;
return optIndex; }
int main() {
int pageFaults = 0;
scanf("%d", &numPages);
scanf("%d",&buffer_size);
int frame[buffer_size];
int pages[numPages];
scanf("%d", &pages[i]);
frame[i] = -1;
int nextIndex = 0;
if (frame[j] == pages[i]) {
pageFault = false;
break;
}
}
if (pageFault) {
frame[replaceIndex] = pages[i];
pageFaults++;
return 0;
}
Output
Enter the number of pages: 14
#include <stdio.h>
#include <stdbool.h>
int lruIndex = 0;
minUsed = used[i];
lruIndex = i;
return lruIndex;
int main() {
scanf("%d", &numPages);
scanf("%d", &buffer_size);
int frame[buffer_size];
int pages[numPages];
int used[numPages] ;
for(int i=0;i<numPages;i++){
used[i]=0;
}
printf("Enter the page number: ");
scanf("%d", &pages[i]);
frame[i] = -1;
int nextIndex = 0;
int lruCount = 0;
if (frame[j] == pages[i]) {
pageFault = false;
used[j] = currentTime++;
break;
if (pageFault) {
frame[lruIndex] = pages[i];
used[lruIndex] = currentTime++;
pageFaults++;
return 0;
}
Output
Enter the number of pages: 14