0% found this document useful (0 votes)
5 views9 pages

micro

REPORT PRESENTATION FOR SOCIAL INTERNSHIP

Uploaded by

c14229705
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)
5 views9 pages

micro

REPORT PRESENTATION FOR SOCIAL INTERNSHIP

Uploaded by

c14229705
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/ 9

Contiguous file allocation

#include <stdio.h>

#define MAX_FILES 10

#define MAX_BLOCKS 20

struct File {

char name[20];

int start_block;

int size;

};

int main() {

struct File files[MAX_FILES];

int disk[MAX_BLOCKS];

int n, i, j, free_blocks = MAX_BLOCKS;

// Initialize disk blocks as free

for (i = 0; i < MAX_BLOCKS; i++) {

disk[i] = 0;

printf("Enter the number of files: ");

scanf("%d", &n);

for (i = 0; i < n; i++) {

printf("\nEnter details for file %d:\n", i + 1);

printf("File name: ");

scanf("%s", files[i].name);
printf("File size (in blocks): ");

scanf("%d", &files[i].size);

// Find a contiguous block of free space

int start_block = -1;

for (j = 0; j < MAX_BLOCKS; j++) {

if (disk[j] == 0) {

if (start_block == -1) {

start_block = j;

if (j - start_block + 1 == files[i].size) {

break;

} else {

start_block = -1;

if (start_block != -1) {

files[i].start_block = start_block;

for (j = start_block; j < start_block + files[i].size; j++) {

disk[j] = 1;

free_blocks -= files[i].size;

printf("File %s allocated at block %d\n", files[i].name, start_block);

} else {

printf("Insufficient contiguous free space for file %s\n",


files[i].name);

}
}

printf("\nFile Allocation Table:\n");

printf("File Name\tStart Block\tSize\n");

for (i = 0; i < n; i++) {

printf("%s\t\t%d\t\t%d\n", files[i].name, files[i].start_block,


files[i].size);

printf("\nDisk Status:\n");

for (i = 0; i < MAX_BLOCKS; i++) {

printf("%d ", disk[i]);

printf("\n");

return 0;

Fifo

#include <stdio.h>

#include <stdlib.h>

#define MAX_SIZE 10

Int queue[MAX_SIZE];

Int front = -1, rear = -1;

Void enqueue(int data) {

If (rear == MAX_SIZE – 1) {
Printf(“Queue is full\n”);

Return;

} else if (front == -1 && rear == -1) {

Front = rear = 0;

} else {

Rear++;

Queue[rear] = data;

Printf(“%d enqueued to queue\n”, data);

Int dequeue() {

If (front == -1 && rear == -1) {

Printf(“Queue is empty\n”);

Return -1;

Int data = queue[front];

If (front == rear) {

Front = rear = -1;

} else {

Front++;

Printf(“%d dequeued from queue\n”, data);

Return data;

Void display() {

If (front == -1 && rear == -1) {

Printf(“Queue is empty\n”);
Return;

Printf(“Queue: “);

For (int i = front; i <= rear; i++) {

Printf(“%d “, queue[i]);

Printf(“\n”);

Int main() {

Enqueue(10);

Enqueue(20);

Enqueue(30);

Display();

Dequeue();

Dequeue();

Display();

Enqueue(40);

Enqueue(50);

Display();

Return 0;

LRU

#include <stdio.h>

#include <limits.h>

#define PAGES 4
#define FRAMES 3

Int main() {

Int pages[] = {7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2};

Int frames[FRAMES];

Int mru[FRAMES]; // Most Recently Used

Int page_faults = 0;

// Initialize frames and MRU array

For (int i = 0; i < FRAMES; i++) {

Frames[i] = -1;

Mru[i] = 0;

For (int i = 0; i < PAGES; i++) {

Int page = pages[i];

Int found = 0;

// Check if page is already in frames

For (int j = 0; j < FRAMES; j++) {

If (frames[j] == page) {

Found = 1;

Mru[j] = i; // Update MRU for this page

Break;

// If page is not found, replace the least recently used page

If (!found) {
Int min_index = 0;

For (int j = 1; j < FRAMES; j++) {

If (mru[j] < mru[min_index]) {

Min_index = j;

Frames[min_index] = page;

Mru[min_index] = i;

Page_faults++;

// Print the current state of frames

Printf(“Frame: “);

For (int j = 0; j < FRAMES; j++) {

Printf(“%d “, frames[j]);

Printf(“\n”);

Printf(“Total Page Faults: %d\n”, page_faults);

Return 0;

FCfS

#include <stdio.h>

Int main() {

Int n, i, j, time, remain, flag = 0, time_quantum;

Int wait_time = 0, turn_around_time = 0, at[10], bt[10], rt[10];


Printf(“Enter Total Process:\t “);

Scanf(“%d”, &n);

Printf(“\nEnter Arrival Time and Burst Time\n”);

For(i = 0; i < n; i++) {

Printf(“Process[%d]\n Arrival Time:\t “, i + 1);

Scanf(“%d”, &at[i]);

Printf(“Burst Time:\t “);

Scanf(“%d”, &bt[i]);

Rt[i] = bt[i];

Rt[0] = bt[0];

Time = bt[0];

Remain = bt[0];

For(time = 0, i = 0; remain != 0; ) {

If(rt[i] <= time && rt[i] > 0) {

Wait_time += time – at[i];

Rt[i] = 0;

Flag = 1;

If(rt[i] > 0) {

Time++;

Rt[i]--;

}
If(i == n – 1 && flag == 1) {

I = 0;

Flag = 0;

Else if(i < n – 1) {

If(rt[i + 1] <= time && rt[i + 1] > 0) {

I++;

Turn_around_time = wait_time + bt[0];

Printf(“\n\nProcess\t|Turn Around Time|Waiting Time\n\n”);

For(i = 0; i < n; i++) {

Printf(“Process[%d]\t|\t %d\t|\t %d\n”, i + 1, turn_around_time,


wait_time);

Printf(“\nAverage Waiting Time=%f\n”, wait_time*1.0/n);

Printf(“Average Turn Around Time=%f”, turn_around_time*1.0/n);

Return 0;

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy