0% found this document useful (0 votes)
7 views5 pages

Amit OS Lab 08

The document outlines an experiment evaluation sheet for a CSE student, Amit Mishra, focusing on implementing the First Fit Algorithm in C programming. It includes theoretical explanations, advantages, and disadvantages of the First Fit memory allocation technique, along with a sample C code implementation. The document concludes that the experiment successfully verified the First Fit Algorithm both theoretically and practically.

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 DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views5 pages

Amit OS Lab 08

The document outlines an experiment evaluation sheet for a CSE student, Amit Mishra, focusing on implementing the First Fit Algorithm in C programming. It includes theoretical explanations, advantages, and disadvantages of the First Fit memory allocation technique, along with a sample C code implementation. The document concludes that the experiment successfully verified the First Fit Algorithm both theoretically and practically.

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 DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

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.


Software required : Terminal, gcc
Theory :
First Fit Algorithm :
First-Fit Allocation is a memory allocation technique used in operating systems
to allocate memory to a process. In First-Fit, the operating system searches
through the list of free blocks of memory, starting from the beginning of the
list, until it finds a block that is large enough to accommodate the memory
request from the process. Once a suitable block is found, the operating system
splits the block into two parts: the portion that will be allocated to the process,
and the remaining free block.
Advantages of First-Fit Allocation include its simplicity and efficiency, as
the search for a suitable block of memory can be performed quickly and
easily. Additionally, First-Fit can also help to minimize memory
fragmentation, as it tends to allocate memory in larger blocks.
Disadvantages of First-Fit Allocation include poor performance in situations
where the memory is highly fragmented, as the search for a suitable block of
memory can become time-consuming and inefficient. Additionally, First-Fit can
also lead to poor memory utilization, as it may allocate larger blocks of
memory than are actually needed by a process.
Overall, First-Fit Allocation is a widely used memory allocation technique
in operating systems, but its effectiveness may vary depending on the
specifics of the system and the workload being executed.
For both fixed and dynamic memory allocation schemes, the operating system
must keep list of each memory location noting which are free and which are
busy. Then as new jobs come into the system, the free partitions 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, allocation[MAX_PROCESSES];
printf("Enter the number of memory blocks: ");
scanf("%d", &n);
printf("Enter the number of processes: ");
scanf("%d", &m);
printf("Enter the sizes of the memory blocks:\n");
for (i = 0; i < n; i++) {
printf("Block %d: ", i + 1);
scanf("%d", &blockSize[i]);
}
printf("Enter the sizes of the processes:\n");
for (i = 0; i < m; i++) {
printf("Process %d: ", i + 1);
scanf("%d", &processSize[i]);
}
for (i = 0; i < m; i++) {
allocation[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] && allocation[i] == -1)
{ allocation[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: Allocation results


printf("\nProcess No. Process Size Block No.\n");
for (i = 0; i < m; i++) {
if (allocation[i] != -1) {
printf("%d\t\t%d\t\t%d\n", i + 1, processSize[i], allocation[i] + 1);
} else {
printf("%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 theoretically and practically.
Amit Mishra Roll No. : 29 Page No. : 04

You might also like