Professional Documents
Culture Documents
Geetika Operating Systems
Geetika Operating Systems
Geetika Operating Systems
of
Operating System
submitted in partial fulfillment of the requirement for the award of the degree of
Bachelor of Technology (B.Tech)
in
Computer Engineering With Data Science
by
Geetika Dua
20001016017
Under the guidance of
Ms. Deepika
int main(){
int n;
cout<<endl<<"Enter number of elements ";
cin>>n;
vector<int>v(n);
cout<<endl<<"Enter the elements ";
for (int i=0;i<n;i++)
{
cin>>v[i];
}
bubbleSort(v,n);
for(int i=0;i<n;i++){
cout<<v[i]<<" ";
}
return 0;
}
WAP to implement Selection Sort
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cout<<endl<<"Enter number of elements ";
cin>>n;
vector<int>v(n);
cout<<endl<<"Enter the elements ";
for (int i=0;i<n;i++)
{
cin>>v[i];
}
cout<<"The sorted array: ";
selectionSort(v,n);
for(int i=0;i<n;i++){
cout<<v[i]<<" ";
}
return 0;
}
WAP to implement Quick Sort
#include<bits/stdc++.h>
using namespace std;
int partition(vector<int>& arr, int low, int high) {
int pivot = arr[high];
int i = low - 1;
for(int j = low; j < high; j++) {
if(arr[j] < pivot) {
i++;
swap(arr[i], arr[j]);
}
}
swap(arr[i+1], arr[high]);
return i+1;
}
void quicksort(vector<int>& arr, int low, int high) {
if(low < high) {
int pi = partition(arr, low, high);
quicksort(arr, low, pi-1);
quicksort(arr, pi+1, high);
}
}
int main() {
int n;
cout<<endl<<"Enter number of elements ";
cin>>n;
vector<int>v(n);
cout<<endl<<"Enter the elements ";
for (int i=0;i<n;i++)
{
cin>>v[i];
}
cout<<"The sorted array: ";
quicksort(v,0,n-1);
for(int i=0;i<n;i++){
cout<<v[i]<<" ";
}
}
WAP to implement First Come, First Serve Scheduling Algorithm
include<bits/stdc++.h>
using namespace std;
int main() {
int n;
cout<<"Enter the number of processes: ";
cin>>n;
int bt[n],wt[n],tat[n],average_wt=0,average_tat=0,i,j;
cout<<"\nEnter the Burst Time of processes\n";
for (i=0;i<n;i++) {
cout<<"P["<<i+1<<"]:";
cin>>bt[i];
}
wt[0]=0;
for (i=1;i<n;i++) {
wt[i]=0;
for (j=0;j<i;j++)
wt[i]+=bt[j];
}
cout<<"\Process Burst Time\tWaiting Time\tTurnaround Time";
for (i=0;i<n;i++) {
tat[i]=bt[i]+wt[i];
average_wt+=wt[i];
average_tat+=tat[i];
cout<<"\nP["<<i+1<<"]"<<"\t\t"<<bt[i]<<"\t\t"<<wt[i]<<"\t\t"<<tat[i];
}
average_wt/=n;
average_tat/=n;
cout<<"\an\nAverage Waiting Time:"<<average_wt;
cout<<"\nAverage Turnaround Time:"<<average_tat;
return 0;
}
WAP to implement Shortest Job First Scheduling Algorithm
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,temp,tt=0,min,d,i,j;
float atat=0,awt=0,stat=0,swt=0;
cout<<"enter no of process"<<endl;
cin>>n;
int a[n],b[n],e[n],tat[n],wt[n];
cout<<"enter arival time \n";
for(i=0;i<n;i++)
{
cin>>a[i];
}
for(i=0;i<n;i++)
{
cout<<"enter brust time ";
cin>>b[i];
}
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(b[i]>b[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
temp=b[i];
b[i]=b[j];
b[j]=temp;
}
}
}
min=a[0];
for(i=0;i<n;i++)
{
if(min>a[i])
{
min=a[i];
d=i;
}
}
tt=min;
e[d]=tt+b[d];
tt=e[d];
for(i=0;i<n;i++)
{
if(a[i]!=min)
{
e[i]=b[i]+tt;
tt=e[i];
}
}
for(i=0;i<n;i++)
{
tat[i]=e[i]-a[i];
stat=stat+tat[i];
wt[i]=tat[i]-b[i];
swt=swt+wt[i];
}
atat=stat/n;
awt=swt/n;
cout<<"Process Arrival-time(s) Burst-time(s) Waiting-time(s) Turnaround-time(s)\n";
for(i=0;i<n;i++)
{
cout<<"P"<<i+1<<" "<<a[i]<<" "<<b[i]<<"
"<<wt[i]<<" "<<tat[i]<<endl;
}
queue<int> q;
float sumTAT;
float sumWT;
for (int i = 0; i < n; i++)
{
printf("%d %d %d %d %d %d\n", i + 1, AT[i], BT[i], CT[i], TAT[i], WT[i]);
sumTAT += TAT[i];
sumWT += WT[i];
}
printf("Average Turn Around Time: %f\n", sumTAT / n);
printf("Average Waiting Time: %f", sumWT / n);
}
WAP to implement FIFO Page Replacement Algorithm.
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main()
{
int pages[] = {3, 2, 1, 0, 3, 2, 4, 3, 2, 1, 0, 4};
int n = sizeof(pages) / sizeof(pages[0]);
int page_slots = 4;
cout << "Page Faults: " << pageFaults(pages, n, page_slots);
}
WAP to implement FCFS Disk Scheduling
#include<bits/stdc++.h>
using namespace std;
int main(){
int a[]={55,58,39,18,90,160,150,38,184};
int seektime=45;
float avg_seektime=0,n=9;
for(int i=1;i<9;i++){
seektime=seektime+abs(a[i]-a[i-1]);
}
avg_seektime=seektime/n;
cout<<avg_seektime;
}
sort(list.begin(), list.end());
for (int i = 0; i < list.size(); i++)
{
if (list[i] == head)
{
head_position = i;
}
}
while (list.size() != 1)
{
if (head_position == 0)
{
seek_count += abs(list[head_position] - list[head_position + 1]);
list.erase(list.begin() + head_position);
}
else if (head_position == list.size() - 1)
{
}
else if (abs(list[head_position] - list[head_position - 1]) < abs(list[head_position]
- list[head_position + 1]))
{
seek_count += abs(list[head_position] - list[head_position - 1]);
list.erase(list.begin() + head_position);
head_position = head_position - 1;
}
else if (abs(list[head_position] - list[head_position - 1]) >=
abs(list[head_position] - list[head_position + 1]))
{
seek_count += abs(list[head_position] - list[head_position + 1]);
list.erase(list.begin() + head_position);
}
}
return seek_count;
}
int main()
{
int request_sequence[] = {55,58,39,18,90,160,150,38,184};
int n = sizeof(request_sequence) / sizeof(request_sequence[0]);
int head = 100;
cout << "Seek Count: " << seekCount(request_sequence, n, head);
}
while (list.size() != 1)
{
if (head_position != (list.size() - 1))
{
seek_count += abs(list[head_position] - list[head_position + 1]);
list.erase(list.begin() + head_position);
}
else
{
seek_count += abs(list[head_position] - list[head_position - 1]);
list.erase(list.begin() + head_position);
head_position--;
}
}
return seek_count;
}
int main()
{
int request_sequence[] = {55,58,39,18,90,160,150,38,184};
int n = sizeof(request_sequence) / sizeof(request_sequence[0]);
int head = 100;
cout << "Seek Count: " << seekCount(request_sequence, n, head);
}
while (list.size() != 1)
{
if (head_position != (list.size() - 1))
{
seek_count += abs(list[head_position] - list[head_position + 1]);
list.erase(list.begin() + head_position);
}
else
{
seek_count += abs(list[head_position] - list[0]);
list.erase(list.begin() + head_position);
head_position = 0;
}
}
return seek_count;
}
int main()
{
int request_sequence[] = {55,58,39,18,90,160,150,38,184};
int n = sizeof(request_sequence) / sizeof(request_sequence[0]);
int head = 100;
cout << "Seek Count: " << seekCount(request_sequence, n, head);
}
#include <bits/stdc++.h>
using namespace std;
while (list.size() != 1)
{
if (head_position != (list.size() - 1))
{
seek_count += abs(list[head_position] - list[head_position + 1]);
list.erase(list.begin() + head_position);
}
else
{
seek_count += abs(list[head_position] - list[head_position - 1]);
list.erase(list.begin() + head_position);
head_position--;
}
}
return seek_count;
}
int main()
{
int request_sequence[] = {55,58,39,18,90,160,150,38,184};
int n = sizeof(request_sequence) / sizeof(request_sequence[0]);
int head = 100;
cout << "Seek Count: " << seekCount(request_sequence, n, head);
}
WAP to implement C-LOOK Disk Scheduling
#include <bits/stdc++.h>
using namespace std;
while (list.size() != 1)
{
if (head_position != (list.size() - 1))
{
seek_count += abs(list[head_position] - list[head_position + 1]);
list.erase(list.begin() + head_position);
}
else
{
seek_count += abs(list[head_position] - list[0]);
list.erase(list.begin() + head_position);
head_position = 0;
}
}
return seek_count;
}
int main()
{
int request_sequence[] = {55,58,39,18,90,160,150,38,184};
int n = sizeof(request_sequence) / sizeof(request_sequence[0]);
int head = 100;
cout << "Seek Count: " << seekCount(request_sequence, n, head);
}