OS Microproject
OS Microproject
MAEER’s MIT
POLYTECHNIC PUNE
MICROPROJECT
PROGRAM: COMPUTER
1
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
Certificate
This is to certify that Mr. Advait Khairnar Roll No : 37 .Of fifth
Semester of Diploma in Computer Engineering of Institute: MIT Polytechnic
Pune (Code:1048) has completed the Micro Project satisfactorily in Subject:
Operating System for the academic year 2022-23 as prescribed in the
curriculum.
2
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
Certificate
This is to certify that Miss Nayan Bhagat Roll No : 39 .Of fifth
Semester of Diploma in Computer Engineering of Institute: MIT Polytechnic
Pune (Code:1048) has completed the Micro Project satisfactorily in Subject:
Operating System for the academic year 2022-23 as prescribed in the
curriculum.
3
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
Index
4
Sr. No. Title Page no.
1. Proposal- A 6
2. Proposal- B 7
3. Abstract 8
4 Introduction 10
5. Implementation 11
6. Output 13
7. Conclusion 14
8. Evaluation sheet 15
5
Subject- Operating System
1.0 Brief Introduction: FIFO and OPTIMAL Algorithm
2.0 Aim of the project: To prepare a FIFO and OPTIMAL Algorithm C
3.0 Action plan:
Sr.no. Details of activity Planned start Planned finish Name of responsible team
date date member
1. Searching for topic 1-11-2022 1-11-2022 Advait Khairnar
2. Surveying 2-11-2022 2-11-2022 Nayan Bhagat
information
3. Requirement 3-11-2022 3-11-2022 Nayan Bhagat
analysis
4. Finalizing layout 4-11-2022 4-11-2022 Advait Khairnar
5. Generating program 5-11-2022 5-11-2022 Advait Khairnar
and final execution
6. Report generation 6-11-2022 6-11-2022 Nayan Bhagat
7. Final submission Nayan Bhagat & Advait
Khairnar
6
Microproject - B
1.0 Brief Introduction: FIFO and OPTIMAL Algorithm
2.0 Aim of the micro-project: To prepare a FIFO and OPTIMAL Algorithm using C.
4.0 Actual procedure followed: The project has been typed in Google document,
information is obtained from Google, code is typed on IntelliJ & execution is done on
Microsoft Edge.
5.0 Actual resources used: Google document, Google chrome, Notepad, Microsoft
Edge, laptop/desktop, visual studios.
Abstract:
FIFO which is also known as First In First Out is one of the types of page replacement
algorithm. The FIFO algorithm is used in the paging method for memory management in an
operating system that decides which existing page needs to be replaced in the queue. FIFO
7
algorithm replaces the oldest (First) page which has been present for the longest time in the
main memory.
In simple words, When a new page comes in from secondary memory to main memory, It
selects the front of the queue which is the oldest page present, and removes it.
Since we have a fixed number of frames and all the processes cannot be stored in the main
memory at a single time hence we use page replacement algorithms to store pages of a
process instead of the whole process.
FIFO algorithm replaces the oldest (First) page which has been present for the longest
time in the main memory.
In simple words, When a new page comes in from secondary memory to main memory, It
selects the front of the queue which is the oldest page present, and removes it.
Why do we need to swap the pages?: Since we have a fixed number of frames and all the
processes cannot be stored in the main memory at a single time hence we use page
replacement algorithms to store pages of a process instead of the whole process.
A page fault generates an alert for the operating system. The operating system then
retrieves the page from the secondary or virtual memory to the main memory. All
the processes run in the background.
Generally, this takes a few milliseconds; still, it has a significant impact on the
performance of the operating system. A high number of page faults can slow down
the whole system. Although page faults are common in modern days operating
systems, a large number of page faults may cause the program to crash or terminate
unexpectedly.
The effectiveness of a page replacement algorithm is measured with the
number of page fault it generates. The more effective the page replacement
algorithm is, the less the number of page faults generated by the algorithm.
Implementation:
//importing libraries and predefined
#include<stdio.h>
#include<conio.h>
//array declaration
int fr[3];
//main function
void main()
8
{
void fifo_algorithm();
int optimal_algorithm();
bool flag = true;
int input;
printf("\nOperating Systems microproject");
printf("This program is to test 'FIRST IN FIRST OUT ALGORITHM' and 'OPTIMAL ALGORITHM'");
while (flag == true) {
printf("\n\nMenu: ");
printf("\n\n(1) FIFO ALGORITHM \n(2) OPTIMAL ALGORITHM");
printf("\n\nchoose an option: ");
scanf_s("%d", &input);
if (input == 1)
{
fifo_algorithm();
flag = false;
}
else if (input == 2)
{
optimal_algorithm();
flag = false;
}
else
{
printf("Wrong value entered");
}
}
}
void fifo_algorithm()
{
void display();
// declaration of variables and arrays
int iteration, j, page[12] = { 2,3,2,1,5,2,4,5,3,2,5,2 };
int flag1 = 0, flag2 = 0, pf = 0, frsize = 3, top = 0;
// process code
for (iteration = 0; iteration < 3; iteration++)
{
fr[iteration] = -1;
}
for (j = 0; j < 12; j++)
{
flag1 = 0;
flag2 = 0;
for (iteration = 0; iteration < 12; iteration++)
{
if (fr[iteration] == page[j])
{
flag1 = 1;
flag2 = 1;
break;
}
}
if (flag1 == 0)
{
9
for (iteration = 0; iteration < frsize; iteration++)
{
if (fr[iteration] == -1)
{
fr[iteration] = page[j];
flag2 = 1;
break;
}
}
}
if (flag2 == 0)
{
fr[top] = page[j];
top++;
pf++;
if (top >= frsize)
top = 0;
}
//call display function
display();
}
// display the process output
printf("Number of page faults : %d ", pf);
}
void display()
{
int iteration;
printf("\n");
for (iteration = 0; iteration < 3; iteration++)
printf("%d\t", fr[iteration]);
}
int optimal_algorithm()
{
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_s("%d", &no_of_frames);
printf("Enter number of pages: ");
scanf_s("%d", &no_of_pages);
printf("Enter page reference string: ");
for (i = 0; i < no_of_pages; ++i) {
scanf_s("%d", &pages[i]);
}
for (i = 0; i < no_of_frames; ++i) {
frames[i] = -1;
}
for (i = 0; i < no_of_pages; ++i) {
flag1 = flag2 = 0;
for (j = 0; j < no_of_frames; ++j) {
if (frames[j] == pages[i]) {
flag1 = flag2 = 1;
10
break;
}
}
if (flag1 == 0) {
for (j = 0; j < no_of_frames; ++j) {
if (frames[j] == -1) {
faults++;
frames[j] = pages[i];
flag2 = 1;
break;
}
}
}
if (flag2 == 0) {
flag3 = 0;
for (j = 0; j < no_of_frames; ++j) {
temp[j] = -1;
for (k = i + 1; k < no_of_pages; ++k) {
if (frames[j] == pages[k]) {
temp[j] = k;
break;
}
}
}
for (j = 0; j < no_of_frames; ++j) {
if (temp[j] == -1) {
pos = j;
flag3 = 1;
break;
}
}
if (flag3 == 0) {
max = temp[0];
pos = 0;
for (j = 1; j < no_of_frames; ++j) {
if (temp[j] > max) {
max = temp[j];
pos = j;
}
}
}
frames[pos] = pages[i];
faults++;
}
printf("\n");
for (j = 0; j < no_of_frames; ++j) {
printf("%d\t", frames[j]);
}
}
printf("\n\nTotal Page Faults = %d", faults);
11
return 0;
}
Output:
12
Conclusion:
In this way, we’ve created a FIFO and OPTIMAL Algorithm. We’ve used C Programming
language to perform this program.
13
Micro-project evaluation sheet.
37 Advait 2001480062
Khairnar
39 Nayan 2001480064
Bhagat
Note: Every teacher is expected to assign marks for group evaluation in first 3
columns and individual evaluation in 4 columns for each of students as per rubics.
Comments/ suggestion about the team work/ leadership/ inter- personal
communication (if
any)________________________________________________________________
__________________________________________
Any other Comment:______________________________________________
Name and designation of the Faculty Member:
Signature:_______________________________________________
14