0% found this document useful (0 votes)
8 views4 pages

Amit OS Lab 08

Uploaded by

Abhijit Logavi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views4 pages

Amit OS Lab 08

Uploaded by

Abhijit Logavi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Student Name : Amit Mishra PRN No.

: 231111062
Course Name : CSE (IoT & CSBC) Course ID : CSL429
Year : SE Semester : IV
Roll No. : 29

EXPERIMENT EVALUATION SHEET

Experiment No. : 08
Experiment Name :

Write a C program to implement First Fit Algorithm

MarksPerformance Correction
Sr No. Evaluation Criteria Date & Sign
(Out of 9) Date
of Instructor

1. Experiment Performance

2. Journal Performance

3. Punctuality

Total
Operating System Lab

Aim : Write a C program to implement First Fit Algorithm.


So ware required : Terminal, gcc
Theory :
First Fit Algorithm :
First-Fit Alloca on is a memory alloca on technique used in opera ng systems
to allocate memory to a process. In First-Fit, the opera ng system searches
through the list of free blocks of memory, star ng from the beginning of the
list, un l it finds a block that is large enough to accommodate the memory
request from the process. Once a suitable block is found, the opera ng system
splits the block into two parts: the por on that will be allocated to the process,
and the remaining free block.
Advantages of First-Fit Alloca on include its simplicity and efficiency, as the
search for a suitable block of memory can be performed quickly and easily.
Addi onally, First-Fit can also help to minimize memory fragmenta on, as it
tends to allocate memory in larger blocks.
Disadvantages of First-Fit Alloca on include poor performance in situa ons
where the memory is highly fragmented, as the search for a suitable block of
memory can become me-consuming and inefficient. Addi onally, First-Fit can
also lead to poor memory u liza on, as it may allocate larger blocks of
memory than are actually needed by a process.
Overall, First-Fit Alloca on is a widely used memory alloca on technique in
opera ng systems, but its effec veness may vary depending on the specifics
of the system and the workload being executed.
For both fixed and dynamic memory alloca on schemes, the opera ng system
must keep list of each memory loca on no ng which are free and which are
busy. Then as new jobs come into the system, the free par ons must be
allocated
Amit Mishra Roll No. : 29 Page No. : 02
Operating System Lab
#include <stdio.h>
#define MAX_BLOCKS 10
#define MAX_PROCESSES 10
int main() {
int blockSize[MAX_BLOCKS], processSize[MAX_PROCESSES];
int n, m, i, j, alloca on[MAX_PROCESSES];
prin ("Enter the number of memory blocks: ");
scanf("%d", &n);
prin ("Enter the number of processes: ");
scanf("%d", &m);
prin ("Enter the sizes of the memory blocks:\n");
for (i = 0; i < n; i++) {
prin ("Block %d: ", i + 1);
scanf("%d", &blockSize[i]);
}
prin ("Enter the sizes of the processes:\n");
for (i = 0; i < m; i++) {
prin ("Process %d: ", i + 1);
scanf("%d", &processSize[i]);
}
for (i = 0; i < m; i++) {
alloca on[i] = -1; // -1 indicates unallocated
}
// First Fit Algo...
for (i = 0; i < m; i++) {
for (j = 0; j < n; j++) {
if (blockSize[j] >= processSize[i] && alloca on[i] == -1) {
alloca on[i] = j; // Allocate process to block
blockSize[j] -= processSize[i]; // Reduce block size
break; // Move to the next process
}
}
}
Amit Mishra Roll No. : 29 Page No. : 03
Operating System Lab

// Output: Alloca on results


prin ("\nProcess No. Process Size Block No.\n");
for (i = 0; i < m; i++) {
if (alloca on[i] != -1) {
prin ("%d\t\t%d\t\t%d\n", i + 1, processSize[i], alloca on[i] + 1);
} else {
prin ("%d\t\t%d\t\tNot Allocated\n", i + 1, processSize[i]);
}
}

return 0;
}
OUTPUT :

CONCLUSION :
Thus, we successfully verified First Fit Algorithm and performed it
both theore cally and prac cally.
Amit Mishra Roll No. : 29 Page No. : 04

You might also like