OS Lab File
OS Lab File
Samalkha (Haryana)
Computer Science & Engineering Department
Affiliated to
( II )
INDEX
FCFS
2. Simulation of CPU scheduling Algorithm:
SJF
3. Simulation of CPU scheduling Algorithm:
Round Robin
Priority
(I)
INDEX
( II )
Name: Anmol Baranwal Roll no: 2820208
Experiment 1.
Simulation of the CPU scheduling algorithm - FCFS
Program:-
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,sumTAT=0,sumWT=0;
cout<<"\n\n";
cout<<"Anmol Baranwal -- 2820208";
cout<<"\n\n";
wt[0]=0;
for(size_t i=1;i<=n;i++){
wt[i]=wt[i-1]+bt[i-1];
cout<<"wt["<<i<<"] "<<wt[i]<<" \n";
sumWT+=wt[i];
}
for(int i=0;i<n;i++){
TAT[i]=wt[i]+bt[i];
sumTAT+=TAT[i];
sumWT+=wt[i];
}
double avgTAT= ((double)sumTAT)/n;
double avgWT= ((double)sumWT)/n;
return 0;
}
1|Page
Name: Anmol Baranwal Roll no: 2820208
OUTPUT:
2|Page
Name: Anmol Baranwal Roll no: 2820208
Experiment 2.
Simulation of the CPU scheduling algorithm - SJF
Program:-
#include <bits/stdc++.h>
using namespace std;
struct Process {
int pid; // Process ID
int bt; // Burst Time
int art; // Arrival Time
};
void findTurnAroundTime(Process proc[], int n, int wt[], int tat[]) {
for (int i = 0; i < n; i++)
tat[i] = proc[i].bt + wt[i];
}
rt[shortest]--;
minm = rt[shortest];
if (minm == 0)
minm = INT_MAX;
if (rt[shortest] == 0) {
complete++;
3|Page
Name: Anmol Baranwal Roll no: 2820208
check = false;
finish_time = t + 1;
// Calculate waiting time
wt[shortest] = finish_time -
proc[shortest].bt -
proc[shortest].art;
if (wt[shortest] < 0)
wt[shortest] = 0;
}
t++;
}
}
findWaitingTime(proc, n, wt);
4|Page
Name: Anmol Baranwal Roll no: 2820208
OUTPUT:
5|Page
Name: Anmol Baranwal Roll no: 2820208
Experiment 3.
Simulation of the CPU scheduling algorithm – Round Robin
Program:-
#include<bits/stdc++.h>
using namespace std;
void findWaitingTime(int processes[] ,int burstTime[], int WT[], int quantum, int n)
{
int remBT[20] {0};
int t=0;
for(int i=0;i<n;i++){
remBT[i]=burstTime[i];
}
while(1){
for(int i=0;i<n;i++){
if(remBT[i] > 0){
finish = false; // the process has some burst time so it has not finished yet
6|Page
Name: Anmol Baranwal Roll no: 2820208
for(int i=0;i<n;i++){
total_WT += WT[i];
total_TAT += TAT[i];
}
cout<<"\n\nAverage Waiting Time ="<< (float)total_WT/(float)n<<"\n";
cout<<"\nAverage Turn Around Time ="<< (float)total_TAT/(float)n<<"\n\n";
}
int main()
{
int processes[20] {0}, n;
cout<<"\n\n";
cout<<"Anmol Baranwal -- 2820208";
cout<<"\n\n";
// int AT[n] {0}, BT[n] {0}, n, quantum=1, WT[n] {0}, TAT[n] {0}, remBT[n] {0};
// int sumTAT=0, sumWT=0;
for(int i=0;i<n;i++){
processes[i]=i+1;
cin>>burstTime[i];
}
OUTPUT:
8|Page
Name: Anmol Baranwal Roll no: 2820208
Experiment 4.
Simulation of the CPU scheduling algorithm - Priority
Program:-
#include<bits/stdc++.h>
using namespace std;
struct Process
{
int pid; // Process ID
int bt; // CPU Burst time required
int priority; // Priority of this process
};
wt[0] = 0;
findWaitingTime(proc, n, wt);
9|Page
Name: Anmol Baranwal Roll no: 2820208
cout << "\nProcesses "<< " Priority " << " Burst time "
<< " Waiting time " << " Turn around time\n";
findavgTime(proc, n);
}
int main()
{
return 0;
}
10 | P a g e
Name: Anmol Baranwal Roll no: 2820208
OUTPUT:
11 | P a g e
Name: Anmol Baranwal Roll no: 2820208
Experiment 5.
Write a program to implement Banker’s Algorithm
Program:-
#include<iostream>
using namespace std;
// Number of processes
const int P = 5;
// Number of resources
const int R = 3;
int count = 0;
while (count < P)
{
bool found = false;
for (int p = 0; p < P; p++)
{
if (finish[p] == 0)
{
int j;
for (j = 0; j < R; j++)
if (need[p][j] > work[j])
break;
if (j == R)
{
12 | P a g e
Name: Anmol Baranwal Roll no: 2820208
safeSeq[count++] = p;
finish[p] = 1;
found = true;
}
}
}
if (found == false){
cout << "System is not in safe state";
return false;
}
}
cout << "System is in safe state.\nSafe"
" sequence is: ";
for (int i = 0; i < P ; i++)
cout << safeSeq[i] << " ";
return true;
}
int main()
{
cout<<"\n\nAnmol Baranwal -- 2820208\n\n";
int processes[] = {0, 1, 2, 3, 4};
int main() {
cout<<"\n\nAnmol Baranwal -- 2820208\n\n";
char job[10][10];
int time[10], avail, tem[10], temp[10];
int safe[10];
int ind = 1, i, j, q, n, t;
cout<<"Enter no of jobs: ";
cin>>n;
for (i = 0; i < n; i++) {
cout<<"Enter name and time: ";
cin>>job[i]>>time[i];
}
cout<<"Enter the available resources:";
cin>>avail;
cout<<"\n";
for (i = 0; i < n; i++) {
temp[i] = time[i];
tem[i] = i;
}
for (i = 0; i < n; i++)
for (j = i + 1; j < n; j++) {
if (temp[i] > temp[j]) {
t = temp[i];
temp[i] = temp[j];
temp[j] = t;
t = tem[i];
tem[i] = tem[j];
tem[j] = t;
}
}
for (i = 0; i < n; i++) {
q = tem[i];
if (time[q] <= avail) {
safe[ind] = tem[i];
avail = avail - tem[q];
cout<<job[safe[ind]];
ind++;
} else {
cout<<"No safe sequence\n";
}
}
cout<<"\nSafe sequence is:";
for (i = 1; i < ind; i++)
cout<<"\n"<< job[safe[i]]<<" "<< time[safe[i]]<<",";
return 0;
}
14 | P a g e
Name: Anmol Baranwal Roll no: 2820208
OUTPUT:
15 | P a g e
Name: Anmol Baranwal Roll no: 2820208
Experiment 6.
Write a program to implement wait-for-graph
Program:-
#include<bits/stdc++.h>
using namespace std;
int main() {
cout << "\n\nAnmol Baranwal -- 2820208\n\n";
cout << "********** Wait for Graph ************\n";
int p[10][2], r[10][2], wfg[10][2], i, j, k, n, m;
cout<<"Enter no. of process : ";
cin>>m;
cout<<"Enter no. of resourses : ";
cin>>n;
cout<<"Enter process request to resources....\n";
for (i = 0; i < m; i++) {
cin>>p[i][1];
if (p[i][1] < 0 || p[i][1] > n) {
cout<<"Please enter valid resource(0-"<<n<<")\n";
i--;
}
}
cout<<"Enter resource assigned to process.....\n";
for (i = 0; i < n; i++) {
cin>>r[i][1];
}
for (i = 0; i < m; i++) {
for (j = 0; j < n; j++) {
if (p[i][1] == j) {
for (k = 0; k < m; k++) {
if (r[j][1] == k) {
wfg[i][1] = k;
k = m;
}
}
j = n;
}
}
}
cout<<"The wait for graph for the given data is : \n";
for (i = 0; i < m; i++) {
if (wfg[i][1] >= 0 && wfg[i][1] < m) {
cout<<"\nProcess P"<<i<<" is waiting for process P"<<wfg[i][1];
}
}
return 0;
}
16 | P a g e
Name: Anmol Baranwal Roll no: 2820208
OUTPUT:
17 | P a g e
Name: Anmol Baranwal Roll no: 2820208
Experiment 7.
Write a program to implement Resource Allocation Group
Program:-
#include<bits/stdc++.h>
#include<conio.h>
using namespace std;
int main() {
cout << "\n\nAnmol Baranwal -- 2820208\n\n";
cout << "********** Resource Allocation Graph ************\n";
cout<<"\nEnter the number of Processes:";
cin>>proc;
cout<<"\nEnter the number of Resources:";
cin>>res;
row = 0;
while (!kbhit()) {
for (i = 0; i < res; i++) {
if (pro[row][i] == 1) {
if (st_pro[row][i] > 1 && flag == 1) {
cout<<"\nDeadlock Occured";
return 0;
}
st_pro[row][i]++;
row = i;
break;
}
}
return 0;
}
st_req[row][i]++;
row = i;
flag = 1;
break;
}
}
}
cout<<"\nNo Deadlock Detected";
return 0;
}
19 | P a g e
Name: Anmol Baranwal Roll no: 2820208
OUTPUT:
20 | P a g e
Name: Anmol Baranwal Roll no: 2820208
Experiment 8.
Write a program to implement Producer Consumer Problem
Program:-
#include<bits/stdc++.h>
using namespace std;
int main() {
cout << "\n\nAnmol Baranwal -- 2820208\n\n";
cout << "********** Producer Consumer Problem ************\n";
int n;
void producer();
void consumer();
int wait(int);
int signal(int);
cout<<"\n1.Producer\n2.Consumer\n3.Exit";
while (1) {
cout<<"\nEnter your choice:";
cin>>n;
switch (n) {
case 1:
if ((mutex == 1) && (empty != 0))
producer();
else
printf("Buffer is full!!");
break;
case 2:
if ((mutex == 1) && (full != 0))
consumer();
else
printf("Buffer is empty!!");
break;
case 3:
return 0;
break;
}
}
return 0;
}
int wait(int s) {
return (--s);
}
int signal(int s) {
21 | P a g e
Name: Anmol Baranwal Roll no: 2820208
return (++s);
}
void producer() {
mutex = wait(mutex);
full = signal(full);
empty = wait(empty);
x++;
cout<<"Producer produces the item "<<x<<endl;
mutex = signal(mutex);
}
void consumer() {
mutex = wait(mutex);
full = wait(full);
empty = signal(empty);
cout<<"Consumer consumes item "<<x<<endl;
x--;
mutex = signal(mutex);
}
22 | P a g e
Name: Anmol Baranwal Roll no: 2820208
OUTPUT
23 | P a g e
Name: Anmol Baranwal Roll no: 2820208
Experiment 9.
Write a program to implement Dining Philosopher Problem
Program:-
#include<stdio.h>
#include<stdlib.h>
#include<pthread.h>
#include<semaphore.h>
#include<unistd.h>
sem_t room;
sem_t chopstick[5];
void * philosopher(void * );
void eat(int);
int main() {
printf("\n\nAnmol Baranwal--2820208\n\n");
printf("********** Dining Philosopher Problem ************\n");
int i, a[5];
pthread_t tid[5];
sem_init( & room, 0, 4);
for (i = 0; i < 5; i++)
sem_init( & chopstick[i], 0, 1);
for (i = 0; i < 5; i++) {
a[i] = i;
pthread_create( & tid[i], NULL, philosopher, (void * ) & a[i]);
}
for (i = 0; i < 5; i++)
pthread_join(tid[i], NULL);
}
void * philosopher(void * num) {
int phil = * (int * ) num;
sem_wait( & room);
printf("\nPhilosopher %d has entered room", phil);
sem_wait( & chopstick[phil]);
sem_wait( & chopstick[(phil + 1) % 5]);
eat(phil);
sleep(2);
printf("\nPhilosopher %d has finished eating", phil);
sem_post( & chopstick[(phil + 1) % 5]);
sem_post( & chopstick[phil]);
sem_post( & room);
}
void eat(int phil) {
printf("\nPhilosopher %d is eating", phil);
}
24 | P a g e
Name: Anmol Baranwal Roll no: 2820208
OUTPUT:
25 | P a g e
Name: Anmol Baranwal Roll no: 2820208
Experiment 10.
Write a program to implement System Calls
Program:-
#include<unistd.h>
#include<fcntl.h>
#include<sys/stat.h>
#include<sys/types.h>
#include<stdio.h>
int main()
{
printf("\n\nAnmol Baranwal-- 2820208\n\n");
int n,fd;
char buff[50]; // declaring buffer
printf("Enter text to write in the file: ");
//read from keyboard, specifying 0 as fd for std input device
//Here, n stores the number of characters
n= read(0, buff, 50);
// creating a new file using open.
fd=open("file",O_CREAT | O_RDWR, 0777);
//writting input data to file (fd)
write(fd, buff, n);
//Write to display (1 is standard fd for output device) write(1, buff, n);
//closing the file
int close(int fd);
return 0;
}
26 | P a g e
Name: Anmol Baranwal Roll no: 2820208
OUTPUT:
27 | P a g e
Name: Anmol Baranwal Roll no: 2820208
Experiment 11.a.
Write a Program for Page Replacement Algorithm - FIFO
Program:-
#include <stdio.h>
int main() {
printf("\n\nAnmol Baranwal--2820208\n\n");
int referenceString[10], pageFaults = 0, m, n, s, pages, frames;
printf("Enter the number of Pages: ");
scanf("%d", & pages);
printf("\nEnter reference string values:\n");
for (m = 0; m < pages; m++) {
printf("Value No. [%d]:\t", m + 1);
scanf("%d", & referenceString[m]);
}
printf("\n What are the total number of frames:\t"); {
scanf("%d", & frames);
}
int temp[frames];
for (m = 0; m < frames; m++) {
temp[m] = -1;
}
for (m = 0; m < pages; m++) {
s = 0;
for (n = 0; n < frames; n++) {
if (referenceString[m] == temp[n]) {
s++;
pageFaults--;
}
}
pageFaults++;
if ((pageFaults <= frames) && (s == 0)) {
temp[m] = referenceString[m];
} else if (s == 0) {
temp[(pageFaults - 1) % frames] = referenceString[m];
}
printf("\n");
for (n = 0; n < frames; n++) {
printf("%d\t", temp[n]);
}
}
printf("\nTotal Page Faults:\t%d\n", pageFaults);
return 0;
}
28 | P a g e
Name: Anmol Baranwal Roll no: 2820208
OUTPUT:
29 | P a g e
Name: Anmol Baranwal Roll no: 2820208
Experiment 11.b.
Write a Program for Optimal Page Replacement Algorithm
Program:-
#include<stdio.h>
int main() {
printf("\n\nAnmol Baranwal--2820208\n\n");
int no_of_frames, no_of_pages, frames[10], pages[30], temp[10], flag1, flag2, flag3, i, j, k, pos,
max, faults = 0;
printf("Enter number of frames: ");
scanf("%d", & no_of_frames);
if (flag3 == 0) {
max = temp[0];
pos = 0;
pos = j;
}
}
}
frames[pos] = pages[i];
faults++;
}
printf("\n");
return 0;
}
31 | P a g e
Name: Anmol Baranwal Roll no: 2820208
OUTPUT:
32 | P a g e
Name: Anmol Baranwal Roll no: 2820208
Experiment 11.c.
Write a Program for Least Recently Used Page Replacement
Program:-
#include<bits/stdc++.h>
using namespace std;
if (s.find(pages[i]) == s.end()) {
int lru = INT_MAX, val;
for (auto it = s.begin(); it != s.end(); it++) {
if (indexes[ * it] < lru) {
lru = indexes[ * it];
val = * it;
}
}
s.erase(val);
s.insert(pages[i]);
page_faults++;
}
indexes[pages[i]] = i;
}
}
return page_faults;
}
int main() {
cout << "\n\nAnmol Baranwal--2820208\n\n";
int pages[] = {7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2};
int n = sizeof(pages) / sizeof(pages[0]);
int capacity = 4;
cout << pageFaults(pages, n, capacity);
return 0;
}
33 | P a g e
Name: Anmol Baranwal Roll no: 2820208
OUTPUT:
34 | P a g e
Name: Anmol Baranwal Roll no: 2820208
Experiment 12.
Write a program to implement File Operations
Program:-
#include <stdio.h>
int main() {
printf("\n\nAnmol Baranwal--2820208\n\n");
FILE
*
fptr;
char name[20];
int age;
float salary;
fptr = fopen("emp.txt", "w");
/*open for writing*/
if (fptr == NULL) {
printf("File does not exists\n");
return 0;
}
printf("Enter the name\n");
scanf("%s", name);
fprintf(fptr, "Name = %s\n", name);
printf("Enter the age\n");
scanf("%d", & age);
fprintf(fptr, "Age = %d\n", age);
printf("Enter the salary\n");
scanf("%f", & salary);
fprintf(fptr, "Salary = %.2f\n", salary);
fclose(fptr);
return 0;
}
35 | P a g e
Name: Anmol Baranwal Roll no: 2820208
OUTPUT:
36 | P a g e
Name: Anmol Baranwal Roll no: 2820208
Experiment 13.a.
Write a program to implement FCFS Disk Scheduling Algorithm
Program:-
#include <bits/stdc++.h>
using namespace std;
int size = 8;
cout << "Total number of seek operations = " << seek_count << endl;
cout << "Seek Sequence is" << endl;
for (int i = 0; i < size; i++) {
cout << arr[i] << endl;
}
}
int main()
{
int arr[size] = { 176, 79, 34, 60, 92, 11, 41, 114 };
int head = 50;
FCFS(arr, head);
return 0;
}
37 | P a g e
Name: Anmol Baranwal Roll no: 2820208
OUTPUT:
38 | P a g e
Name: Anmol Baranwal Roll no: 2820208
Experiment 13.b.
Write a program to implement SSTF Disk Scheduling Algorithm
Program:-
#include<bits/stdc++.h>
using namespace std;
39 | P a g e
Name: Anmol Baranwal Roll no: 2820208
// Driver code
int main()
{
cout << "\n\nAnmol Baranwal--2820208\n\n";
int n = 8;
int proc[n] = { 176, 79, 34, 60, 92, 11, 41, 114 };
return 0;
}
40 | P a g e
Name: Anmol Baranwal Roll no: 2820208
OUTPUT:
41 | P a g e
Name: Anmol Baranwal Roll no: 2820208
Experiment 13.c.
Write a program to implement SCAN Disk Scheduling
Program:-
#include <bits/stdc++.h>
using namespace std;
int size = 8;
int disk_size = 200;
cout << "Total number of seek operations = " << seek_count << endl;
cout << "Seek Sequence is" << endl;
for (int i = 0; i < seek_sequence.size(); i++) {
cout << seek_sequence[i] << endl;
}
}
// Driver code
int main()
{
cout << "\n\nAnmol Baranwal--2820208\n\n";
// request array
int arr[size] = { 176, 79, 34, 60, 92, 11, 41, 114 };
int head = 50;
string direction = "left";
SCAN(arr, head, direction);
return 0;
}
43 | P a g e
Name: Anmol Baranwal Roll no: 2820208
OUTPUT:
44 | P a g e
Name: Anmol Baranwal Roll no: 2820208
Experiment 13.d.
Write a program to implement C-SCAN Disk Scheduling
Program:-
#include <bits/stdc++.h>
using namespace std;
int size = 8;
int disk_size = 200;
seek_count += distance;
head = cur_track;
}
cout << "Total number of seek operations = " << seek_count << endl;
cout << "Seek Sequence is" << endl;
for (int i = 0; i < seek_sequence.size(); i++) {
45 | P a g e
Name: Anmol Baranwal Roll no: 2820208
int main() {
cout << "\n\nAnmol Baranwal--2820208\n\n";
int arr[size] = { 176, 79, 34, 60, 92, 11, 41, 114 };
int head = 50;
cout << "Initial position of head: " << head << endl;
CSCAN(arr, head);
return 0;
}
46 | P a g e
Name: Anmol Baranwal Roll no: 2820208
OUTPUT:
47 | P a g e
Name: Anmol Baranwal Roll no: 2820208
Experiment 13.e.
Write a program to implement LOOK Disk Scheduling
Program:-
#include <bits/stdc++.h>
using namespace std;
int size = 8;
int disk_size = 200;
int run = 2;
while (run--) {
if (direction == "left") {
for (int i = left.size() - 1; i >= 0; i--) {
cur_track = left[i];
seek_sequence.push_back(cur_track);
distance = abs(cur_track - head);
seek_count += distance;
head = cur_track;
}
direction = "right";
} else if (direction == "right") {
for (int i = 0; i < right.size(); i++) {
cur_track = right[i];
seek_sequence.push_back(cur_track);
cout << "Total number of seek operations = " << seek_count << endl;
cout << "Seek Sequence is" << endl;
cout << "Initial position of head: " << head << endl;
LOOK(arr, head, direction);
return 0;
}
49 | P a g e
Name: Anmol Baranwal Roll no: 2820208
OUTPUT:
50 | P a g e
Name: Anmol Baranwal Roll no: 2820208
Experiment 13.f.
Write a program to implement C-LOOK Disk Scheduling
Program:-
#include <bits/stdc++.h>
using namespace std;
int size = 8;
int disk_size = 200;
seek_sequence.push_back(cur_track);
distance = abs(cur_track - head);
seek_count += distance;
head = cur_track;
}
seek_count += abs(head - left[0]);
head = left[0];
51 | P a g e
Name: Anmol Baranwal Roll no: 2820208
int main() {
cout << "\n\nAnmol Baranwal--2820208\n\n";
int arr[size] = { 176, 79, 34, 60, 92, 11, 41, 114 };
int head = 50;
cout << "Initial position of head: " << head << endl;
CLOOK(arr, head);
return 0;
}
52 | P a g e
Name: Anmol Baranwal Roll no: 2820208
OUTPUT:
53 | P a g e
Name: Anmol Baranwal Roll no: 2820208
Experiment 14.a.
Write a program to implement First Fit partition allocation method.
Program:-
#include<iostream>
using namespace std;
int main() {
cout << "\n\nAnmol Baranwal--2820208\n\n";
int fragment[20], b[20], p[20], i, j, nb, np, temp, lowest = 9999;
static int barray[20], parray[20];
cout << "\n\t\t\tMemory Management Scheme - Best Fit";
cout << "\nEnter the number of blocks:";
cin >> nb;
cout << "Enter the number of processes:";
cin >> np;
cout << "\nEnter the size of the blocks:-\n";
for (i = 1; i <= nb; i++) {
cout << "Block no." << i << ":";
cin >> b[i];
}
cout << "\nEnter the size of the processes :-\n";
for (i = 1; i <= np; i++) {
cout << "Process no. " << i << ":";
cin >> p[i];
}
for (i = 1; i <= np; i++) {
for (j = 1; j <= nb; j++) {
if (barray[j] != 1) {
temp = b[j] - p[i];
if (temp >= 0)
if (lowest > temp) {
parray[i] = j;
lowest = temp;
}
}
}
fragment[i] = lowest;
barray[parray[i]] = 1;
lowest = 10000;
}
cout << "\nProcess_no\tProcess_size\tBlock_no\tBlock_size\tFragment";
for (i = 1; i <= np && parray[i] != 0; i++)
cout << "\n" << i << "\t\t" << p[i] << "\t\t" << parray[i] << "\t\t" << b[parray[i]] << "\t\t" <<
fragment[i];
return 0;
}
54 | P a g e
Name: Anmol Baranwal Roll no: 2820208
OUTPUT:
55 | P a g e
Name: Anmol Baranwal Roll no: 2820208
Experiment 14.b.
Write a program to implement Best Fit partition allocation method.
Program:-
#include<iostream>
using namespace std;
int main() {
cout << "\n\nAnmol Baranwal--2820208\n\n";
int fragment[20], b[20], p[20], i, j, nb, np, temp, lowest = 9999;
static int barray[20], parray[20];
cout << "\n\t\t\tMemory Management Scheme - Best Fit";
cout << "\nEnter the number of blocks:";
cin >> nb;
cout << "Enter the number of processes:";
cin >> np;
cout << "\nEnter the size of the blocks:-\n";
for (i = 1; i <= nb; i++) {
cout << "Block no." << i << ":";
cin >> b[i];
}
cout << "\nEnter the size of the processes :-\n";
for (i = 1; i <= np; i++) {
cout << "Process no. " << i << ":";
cin >> p[i];
}
for (i = 1; i <= np; i++) {
for (j = 1; j <= nb; j++) {
if (barray[j] != 1) {
temp = b[j] - p[i];
if (temp >= 0)
if (lowest > temp) {
parray[i] = j;
lowest = temp;
}
}
}
fragment[i] = lowest;
barray[parray[i]] = 1;
lowest = 10000;
}
cout << "\nProcess_no\tProcess_size\tBlock_no\tBlock_size\tFragment";
for (i = 1; i <= np && parray[i] != 0; i++)
cout << "\n" << i << "\t\t" << p[i] << "\t\t" << parray[i] << "\t\t" << b[parray[i]] << "\t\t" <<
fragment[i];
return 0;
}
56 | P a g e
Name: Anmol Baranwal Roll no: 2820208
OUTPUT:
57 | P a g e
Name: Anmol Baranwal Roll no: 2820208
Experiment 14.c.
Write a program to implement Worst Fit partition allocation method.
Program:-
#include<bits/stdc++.h>
using namespace std;
58 | P a g e
Name: Anmol Baranwal Roll no: 2820208
// Driver code
int main()
{
cout << "\n\nAnmol Baranwal--2820208\n\n";
int blockSize[] = {100, 500, 200, 300, 600};
int processSize[] = {212, 417, 112, 426};
int m = sizeof(blockSize) / sizeof(blockSize[0]);
int n = sizeof(processSize) / sizeof(processSize[0]);
return 0;
}
59 | P a g e
Name: Anmol Baranwal Roll no: 2820208
OUTPUT:
60 | P a g e
Name: Anmol Baranwal Roll no: 2820208
Experiment 14.d.
Write a program to implement Next Fit partition allocation method.
Program:-
#include <bits/stdc++.h>
using namespace std;
// Driver program
61 | P a g e
Name: Anmol Baranwal Roll no: 2820208
int main() {
cout << "\n\nAnmol Baranwal--2820208\n\n";
int blockSize[] = { 5, 10, 20 };
int processSize[] = { 10, 20, 5 };
int m = sizeof(blockSize) / sizeof(blockSize[0]);
int n = sizeof(processSize) / sizeof(processSize[0]);
return 0;
}
62 | P a g e
Name: Anmol Baranwal Roll no: 2820208
OUTPUT:
63 | P a g e