Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
1 views

OSFileLess

The document outlines the study of hardware and software requirements for various operating systems including Windows, Linux, and Unix, along with a comparative analysis of their features, advantages, and disadvantages. It also details the minimum hardware and software requirements for each OS and provides examples of UNIX system calls for process, file, and input/output management. Additionally, it includes implementations of different CPU scheduling algorithms such as FCFS, SJF, and Priority Scheduling.

Uploaded by

Dreadcore
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

OSFileLess

The document outlines the study of hardware and software requirements for various operating systems including Windows, Linux, and Unix, along with a comparative analysis of their features, advantages, and disadvantages. It also details the minimum hardware and software requirements for each OS and provides examples of UNIX system calls for process, file, and input/output management. Additionally, it includes implementations of different CPU scheduling algorithms such as FCFS, SJF, and Priority Scheduling.

Uploaded by

Dreadcore
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 41

EXPERIMENT 1

Aim-: Study of hardware and software requirements of different operating


systems(UNIX, LINUX, WINDOWS XP, WINDOWS7/8.
OPERATING SYSTEM
An operating system acts as an interface between the software and different parts of the computer or
the computer hardware. The operating system is designed in such a way that it can manage the overall
resources and operations of the computer. It is a fully integrated set of specialized programs that handle
all the operations of the computer.

TYPES OF OPERATING SYSTEM


● Windows
● Linux
● Unix

COMPARATIVE ANANYSIS OF VARIOUS OS


Parameters Windows Linux Unix

Cost Less Costly Free More Costly

Ease of use Easy to use Littly difficult for first Easy to use
time user

Security More prone to attack More vulnerable than Less prone to attacks
Unix but less than
Windows

Gaming More games are Less games are present Less games are present
present.

Development and Developed and Linux is open sourced Most of Unix system are
Distribution distributed by Microsoft and distributed by developed by AT&T with
various vendors other commercial
vendors and non profit
organization.

Operating System Lab(KCS-451) Prashant Yadav 2100910100131


ADVANTAGES AND DISADVANTAGES OF VARIOUS OPERATING SYSTEM
1. WINDOWS
Advantages
● User friendly interface and easy to use
● Compatible to all hardware
● Support plug and play feature
● Provide software Development support
● Have both Desktop and touch screen support

Disadvantages
● Security Concerns
● Paid software
● Infection assults
● Rebooting a framework
● High Performance System Required

2. LINUX
Advantages
● Open Source
● No antivirus software needed
● Low system specifications
● No reboot needed for installing/uninstalling
● Less disk space needed

Operating System Lab(KCS-451) Prashant Yadav 2100910100131


Disadvantages
● Software compatibility
● Gaming
● Limited software Availability
● Hardware Compatibility
● Learning curve

3. UNIX
Advantages
● Very stable
● Less code to execute
● Ideal for web hosting
● Safe and secure
● Multitasking

Disadvantages
● Not user friendly
● Cryptic commands
● Gaming
● Less softwares are available
● Software Compatibility

HARDWARE AND SOFTWARE MINIMUM REQUIREMENTS

Operating System Lab(KCS-451) Prashant Yadav 2100910100131


1 WINDOWS 10
● Processor: 1 Gigahertz (GHz) or faster processor.
● RAM: 1 gigabyte (GB) for 32-bit OS or 2GB for 64-bit OS.
● Hard disk Space: 16 Gb for 32-bit OS or 20GB for 64-bit OS.
2 Windows XP
● Pentium 233 MHz processor or faster.
● At least 64 MB of RAM (128 MB is recommended).
● At least 1.5 GB of available space.
3 LINUX
● 32-bit Intel-compatible processor running at 2GHz or greater.
● 512 MB RAM
● Disk space- 2.5 Gb for pipeline Pilot server plus components
● A DVD –ROM drive
4 UNIX
● RAM:1 GB
● Processor: IBM 604e processor with a clock speed of 375 MHz or faster
● Disk space: 1GB free disk space

EXPERIMENT 2

Operating System Lab(KCS-451) Prashant Yadav 2100910100131


Aim-: Execute various UNIX system calls for
i. Process management
ii. File management
iii. Input/output Systems calls

COMMONLY USED UNIX SYSTEM CALLS FOR PROCESS MANAGEMENT:


● fork(): Creates a new process by duplicating the existing process.
● wait(): Suspends the execution of the current process until one of its child processes terminates.
● waitpid(): Suspends the execution of the current process until a specific child process
terminates.
● waitid(): Suspends the execution of the current process until a specific child process or group of
child processes terminates.
● exit(): Terminates the current process and returns the exit status to the parent process.
● kill(): Sends a signal to a specified process.
● getpid(): Returns the process ID (PID) of the current process.
● getppid(): Returns the PID of the parent process of the current process.
● getpgrp(): Returns the process group ID of the current process.
● setpgid(): Sets the process group ID of a process.
● setsid(): Creates a new session and sets the process group ID.
● nice(): Modifies the priority of a process.
● setpriority(): Sets the priority of a process.
● getpriority(): Gets the priority of a process.
● sched_yield(): Yields the processor to other processes.
● getrusage(): Gets resource usage statistics for the current or child processes.
● times(): Gets the current process and system times.
● getrlimit(): Gets the resource limits for the current process.
● setrlimit(): Sets the resource limits for the current process.

COMMONLY USED UNIX SYSTEM CALLS FOR FILE MANAGEMENT:


● open(): Opens a file or creates a new file if it doesn't exist.

Operating System Lab(KCS-451) Prashant Yadav 2100910100131


● close(): Closes a file descriptor.
● read(): Reads data from a file.
● write(): Writes data to a file.
● lseek(): Changes the file offset (position) within a file.
● unlink(): Deletes a file.
● rename(): Renames a file.
● chmod(): Changes the permissions of a file.
● chown(): Changes the owner and group of a file.
● mkdir(): Creates a new directory.
● rmdir(): Deletes an empty directory.
● opendir(): Opens a directory for reading.
● readdir(): Reads the next directory entry.
● closedir(): Closes a directory.
● link(): Creates a hard link to a file.
● symlink(): Creates a symbolic (soft) link to a file.
● readlink(): Reads the value of a symbolic link.
● chdir(): Changes the current working directory.
● getcwd(): Gets the current working directory.

COMMONLY USED UNIX SYSTEM CALLS FOR INPUT/OUTPUT SYSTEM


CALL:
● open(): Opens a file or creates a new file if it doesn't exist.
● close(): Closes a file descriptor.
● read(): Reads data from a file descriptor.
● write(): Writes data to a file descriptor.
● ioctl(): Performs device-specific input/output operations (e.g., configuring a serial port).
● select(): Monitors multiple file descriptors for read/write/exception events.
● poll(): Polls multiple file descriptors for events.
● recv() and send(): Receives and sends data over a network socket.
● socket(): Creates a new network socket.
● bind(): Associates a socket with a local address.
● listen(): Puts a socket into a passive listening mode.

Operating System Lab(KCS-451) Prashant Yadav 2100910100131


● accept(): Accepts an incoming network connection on a listening socket.
● connect(): Initiates a connection to a remote network address.
● shutdown(): Shuts down all or part of a network connection.
● pipe(): Creates an interprocess communication (IPC) pipe.
● dup() and dup2(): Duplicates a file descriptor.
● fsync(): Flushes changes to a file to disk.
● ftruncate(): Truncates a file to a specified size.
● pread() and pwrite(): Reads and writes data at a specific offset within a file.

EXPERIMENT 3.1

Operating System Lab(KCS-451) Prashant Yadav 2100910100131


Aim-: Implement FCFS CPU Scheduling:

PROGRAM
#include <stdio.h>

int main()

{ int i,n;

printf("p no.= process number\t at=arrival time\t bt=Burst time\t ct=Completion time\t tat=Turn
around time\t wt=waiting time\n");

printf("enter total number of process = ");

scanf("%d",&n);

int p[15];

int at[15];

int bt[15];

printf("enter the arrival time in sorted order\n");

for(i=1;i<(n+1);i++)

printf("enter arrival time of p%d = ",i);

scanf("%d",&at[i]);

for(i=1;i<(n+1);i++)

printf("enter Burst time of p%d = ",i);

scanf("%d",&bt[i]);

int ct[15];

ct[0]=0;

for(i=1;i<(n+1);i++)

Operating System Lab(KCS-451) Prashant Yadav 2100910100131


ct[i]=ct[i-1]+bt[i];

int tat[15];

for(i=1;i<(n+1);i++)

tat[i]=ct[i]-at[i];

int wt[15];

for(i=1;i<(n+1);i++)

wt[i]=tat[i]-bt[i];

float avgtat,avgwt;

avgtat=0.0;

avgwt=0.0;

for(i=1;i<(n+1);i++)

avgtat=avgtat+tat[i];

for(i=1;i<(n+1);i++)

avgwt=avgwt+wt[i];

avgtat=avgtat/n;

avgwt=avgwt/n;

printf("p no.\tat\tbt\tct\ttat\twt\n");

for(i=1;i<(n+1);i++)

Operating System Lab(KCS-451) Prashant Yadav 2100910100131


printf("p%d\t%d\t%d\t%d\t%d\t%d\n",i,at[i],bt[i],ct[i],tat[i],wt[i]);

printf("average Turn around time:%f\n",avgtat);

printf("average Waiting time:%f",avgwt);

return 0;

OUTPUT

EXPERIMENT 3.2(a)
Aim-: Implement SJF CPU Scheduling:

Operating System Lab(KCS-451) Prashant Yadav 2100910100131


SJF SCHEDULING
PROGRAM
#include<stdio.h>

int main() {

int time, burst_time[10], at[10], sum_burst_time = 0, smallest, n, i;

int sumt = 0, sumw = 0;

printf("enter the no of processes : ");

scanf("%d", & n);

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

printf("the arrival time for process P%d : ", i + 1);

scanf("%d", & at[i]);

printf("the burst time for process P%d : ", i + 1);

scanf("%d", & burst_time[i]);

sum_burst_time += burst_time[i];

burst_time[9] = 9999;

for (time = 0; time < sum_burst_time;) {

smallest = 9;

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

if (at[i] <= time && burst_time[i] > 0 && burst_time[i] < burst_time[smallest])

smallest = i;

printf("P[%d]\t|\t%d\t|\t%d\n", smallest + 1, time + burst_time[smallest] - at[smallest], time -


at[smallest]);

sumt += time + burst_time[smallest] - at[smallest];

sumw += time - at[smallest];

time += burst_time[smallest];

Operating System Lab(KCS-451) Prashant Yadav 2100910100131


burst_time[smallest] = 0;

printf("\n\n average waiting time = %f", sumw * 1.0 / n);

printf("\n\n average turnaround time = %f", sumt * 1.0 / n);

return 0;

OUTPUT

EXPERIMENT 3.2(b)
Aim-: Implement SJF CPU Scheduling:

Operating System Lab(KCS-451) Prashant Yadav 2100910100131


SRTF SCHEDULING
PROGRAM
#include <stdio.h>

int main()

int a[10],b[10],x[10],i,j,smallest,count=0,time,n;

double avg=0,tt=0,end;

printf("enter the number of Processes:\n");

scanf("%d",&n);

printf("enter arrival time\n");

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

scanf("%d",&a[i]);

printf("enter burst time\n");

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

scanf("%d",&b[i]);

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

x[i]=b[i];

b[9]=9999;

for(time=0;count!=n;time++)

smallest=9;

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

if(a[i]<=time && b[i]<b[smallest] && b[i]>0 )

Operating System Lab(KCS-451) Prashant Yadav 2100910100131


smallest=i;

b[smallest]--;

if(b[smallest]==0)

count++;

end=time+1;

avg=avg+end-a[smallest]-x[smallest];

tt= tt+end-a[smallest];

printf("\n\nAverage waiting time = %lf\n",avg/n);

printf("Average Turnaround time = %lf",tt/n);

return 0;

OUTPUT

EXPERIMENT 3.3(a)
Aim-: Implement PRIORITY CPU Scheduling:

PRIORITY SCHEDULING(non preemptive)

Operating System Lab(KCS-451) Prashant Yadav 2100910100131


PROGRAM
#include <stdio.h>

void swap(int *a,int *b)

int temp=*a;

*a=*b;

*b=temp;

int main()

int n;

printf("Enter Number of Processes: ");

scanf("%d",&n);

int burst[n],priority[n],index[n];

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

printf("Enter Burst Time and Priority Value for Process %d: ",i+1);

scanf("%d %d",&burst[i],&priority[i]);

index[i]=i+1;

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

int temp=priority[i],m=i;

for(int j=i;j<n;j++)

if(priority[j] > temp)

Operating System Lab(KCS-451) Prashant Yadav 2100910100131


temp=priority[j];

m=j;

swap(&priority[i], &priority[m]);

swap(&burst[i], &burst[m]);

swap(&index[i],&index[m]);

int t=0;

printf("Order of process Execution is\n");

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

printf("P%d is executed from %d to %d\n",index[i],t,t+burst[i]);

t+=burst[i];

printf("\n");

printf("Process Id\tBurst Time\tWait Time\n");

int wait_time=0;

int total_wait_time = 0;

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

printf("P%d\t\t%d\t\t%d\n",index[i],burst[i],wait_time);

total_wait_time += wait_time;

wait_time += burst[i];

float avg_wait_time = (float) total_wait_time / n;

printf("Average waiting time is %f\n", avg_wait_time);

Operating System Lab(KCS-451) Prashant Yadav 2100910100131


int total_Turn_Around = 0;

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

total_Turn_Around += burst[i];

float avg_Turn_Around = (float) total_Turn_Around / n;

printf("Average TurnAround Time is %f",avg_Turn_Around);

return 0;

OUTPUT

EXPERIMENT 3.3(b)
Aim-: Implement PRIORITY CPU Scheduling:

Operating System Lab(KCS-451) Prashant Yadav 2100910100131


PRIORITY SCHEDULING(Preemptive)
PROGRAM
#include<stdio.h>

struct process

int WT,AT,BT,TAT,PT;

};

struct process a[10];

int main()

int n,temp[10],t,count=0,short_p;

float total_WT=0,total_TAT=0,Avg_WT,Avg_TAT;

printf("Enter the number of the process\n");

scanf("%d",&n);

printf("Enter the arrival time , burst time and priority of the process\n");

printf("AT BT PT\n");

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

scanf("%d%d%d",&a[i].AT,&a[i].BT,&a[i].PT);

// copying the burst time in

// a temp array fot futher use

temp[i]=a[i].BT;

// we initialize the burst time

Operating System Lab(KCS-451) Prashant Yadav 2100910100131


// of a process with maximum

a[9].PT=10000;

for(t=0;count!=n;t++)

short_p=9;

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

if(a[short_p].PT>a[i].PT && a[i].AT<=t && a[i].BT>0)

short_p=i;

a[short_p].BT=a[short_p].BT-1;

// if any process is completed

if(a[short_p].BT==0)

// one process is completed

// so count increases by 1

count++;

a[short_p].WT=t+1-a[short_p].AT-temp[short_p];

a[short_p].TAT=t+1-a[short_p].AT;

// total calculation

total_WT=total_WT+a[short_p].WT;

total_TAT=total_TAT+a[short_p].TAT;

Avg_WT=total_WT/n;

Operating System Lab(KCS-451) Prashant Yadav 2100910100131


Avg_TAT=total_TAT/n;

// printing of the answer

printf("ID WT TAT\n");

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

printf("%d %d\t%d\n",i+1,a[i].WT,a[i].TAT);

printf("Avg waiting time of the process is %f\n",Avg_WT);

printf("Avg turn around time of the process is %f\n",Avg_TAT);

return 0;

OUTPUT

EXPERIMENT 3.4
Aim-: Implement ROUND ROBIN CPU Scheduling:

Operating System Lab(KCS-451) Prashant Yadav 2100910100131


PROGRAM
#include<stdio.h>

int main()

{ printf("ENTER THE PROCESS IN ASCENDING ORDER WITH RESPECT TO ARRIVAL TIME");

int i, limit, total = 0, x, counter = 0, time_quantum;

int wait_time = 0, turnaround_time = 0, arrival_time[10], burst_time[10], temp[10];

float average_wait_time, average_turnaround_time;

printf("\nEnter Total Number of Processes:\t");

scanf("%d", &limit);

x = limit;

for(i = 0; i < limit; i++)

printf("\nEnter Details of Process[%d]\n", i + 1);

printf("Arrival Time:\t");

scanf("%d", &arrival_time[i]);

printf("Burst Time:\t");

scanf("%d", &burst_time[i]);

temp[i] = burst_time[i];

printf("\nEnter Time Quantum:\t");

Operating System Lab(KCS-451) Prashant Yadav 2100910100131


scanf("%d", &time_quantum);

printf("\nProcess ID\t\tBurst Time\t Turn around Time\t Waiting Time\n");

for(total = 0, i = 0; x != 0;)

if(temp[i] <= time_quantum && temp[i] > 0)

total = total + temp[i];

temp[i] = 0;

counter = 1;

else if(temp[i] > 0)

temp[i] = temp[i] - time_quantum;

total = total + time_quantum;

if(temp[i] == 0 && counter == 1)

x--;

printf("\nProcess[%d]\t\t%d\t\t %d\t\t\t %d", i + 1, burst_time[i], total - arrival_time[i], total -


arrival_time[i] - burst_time[i]);

wait_time = wait_time + total - arrival_time[i] - burst_time[i];

turnaround_time = turnaround_time + total - arrival_time[i];

counter = 0;

if(i == limit - 1)

i = 0;

Operating System Lab(KCS-451) Prashant Yadav 2100910100131


else if(arrival_time[i + 1] <= total)

i++;

else

i = 0;

average_wait_time = wait_time * 1.0 / limit;

average_turnaround_time = turnaround_time * 1.0 / limit;

printf("\n\nAverage Waiting Time:\t%f", average_wait_time);

printf("\nAvg Turn around Time:\t%f\n", average_turnaround_time);

return 0;

OUTPUT

Operating System Lab(KCS-451) Prashant Yadav 2100910100131


EXPERIMENT 4
Aim-: Implementation of Banker’s algorithm.

Operating System Lab(KCS-451) Prashant Yadav 2100910100131


PROGRAM
#include <stdio.h>

#define MAX_PROCESSES 10

#define MAX_RESOURCES 10

int main() {

int available[MAX_RESOURCES];

int max_claim[MAX_PROCESSES][MAX_RESOURCES];

int allocation[MAX_PROCESSES][MAX_RESOURCES];

int need[MAX_PROCESSES][MAX_RESOURCES];

int work[MAX_RESOURCES];

int finish[MAX_PROCESSES];

int safe_sequence[MAX_PROCESSES];

int num_processes, num_resources;

int i, j, k;

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

scanf("%d", &num_processes);

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

scanf("%d", &num_resources);

printf("Enter the available resources:\n");

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

scanf("%d", &available[i]);

printf("Enter the maximum claim of each process:\n");

for (i = 0; i < num_processes; i++)

Operating System Lab(KCS-451) Prashant Yadav 2100910100131


printf("Process %d: ", i);

for (j = 0; j < num_resources; j++)

scanf("%d", &max_claim[i][j]);

printf("Enter the resource allocation to each process:\n");

for (i = 0; i < num_processes; i++)

printf("Process %d: ", i);

for (j = 0; j < num_resources; j++)

scanf("%d", &allocation[i][j]);

need[i][j] = max_claim[i][j] - allocation[i][j];

finish[i] = 0;

for (i = 0; i < num_resources; i++)

work[i] = available[i];

int count = 0;

while (count < num_processes)

int found = 0;

for (i = 0; i < num_processes; i++)

if (!finish[i])

Operating System Lab(KCS-451) Prashant Yadav 2100910100131


{

int j;

for (j = 0; j < num_resources; j++)

if (need[i][j] > work[j])

break;

if (j == num_resources)

for (k = 0; k < num_resources; k++)

work[k] += allocation[i][k];

safe_sequence[count] = i;

finish[i] = 1;

found = 1;

count++;

if (!found)

printf("System is in an unsafe state.\n");

return 0;

printf("Safe sequence: ");

Operating System Lab(KCS-451) Prashant Yadav 2100910100131


for (i = 0; i < num_processes; i++)

printf("P%d ",safe_sequence[i]);

printf("\n");

return 0;

OUTPUT

EXPERIMENT 5
Aim-: Implementation of resource allocation graph(RAG).

Operating System Lab(KCS-451) Prashant Yadav 2100910100131


PROGRAM
#include <stdio.h> int main()

int alloc[10][10],request[10][10],avail[10],r[10],mark[10],w[10]; int i,j,m,n;

printf("Enter the number of process\n"); scanf("%d",&n);

printf("Enter the number of resources\n"); scanf("%d",&m);

for(i=0;i<m;i++)

printf("R%d Resource\n",i); scanf("%d",&r[i]);

printf("Enter the request matrix\n"); for(i=0;i<n;i++)

for(j=0;j<m;j++) scanf("%d",&request[i][j]);

printf("Enter the allocation matrix\n"); for(i=0;i<n;i++)

for(j=0;j<m;j++) scanf("%d",&alloc[i][j]); for(j=0;j<m;j++)

avail[j]=r[j];

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

avail[j]-=alloc[i][j];

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

int count=0; for(j=0;j<m;j++)

Operating System Lab(KCS-451) Prashant Yadav 2100910100131


{

if(alloc[i][j]==0) count++;

else break;

if(count==m) mark[i]=1;

for(j=0;j<m; j++) w[j]=avail[j]; for(i=0;i<n; i++)

int canbeprocessed= 0; if(mark[i]!=1)

for(j=0;j<m;j++)

if(request[i][j]<=w[j]) canbeprocessed=1;

else

canbeprocessed=0; break;

if(canbeprocessed)

mark[i]=1; for(j=0;j<m;j++) w[j]+=alloc[i][j];

Operating System Lab(KCS-451) Prashant Yadav 2100910100131


}

int deadlock=0; for(i=0;i<n;i++) if(mark[i]!=1) deadlock=1;

if(deadlock)

printf("\n Deadlock detected"); else

printf("\n No Deadlock possible");

OUTPUT

EXPERIMENT 6.1
Aim-: Implementation of contiguous allocation techniques.
1. WORST FIT

Operating System Lab(KCS-451) Prashant Yadav 2100910100131


PROGRAM
#include <stdio.h>

#define MAX_BLOCKS 100

#define MAX_PROCESSES 100

struct Block

int size;

int allocated;

};

void allocateMemory(struct Block blocks[], int numBlocks, int processSizes[], int numProcesses)

int i, j, worstFitIndex;

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

worstFitIndex = -1;

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

if (!blocks[j].allocated && blocks[j].size >= processSizes[i])

if (worstFitIndex == -1 || blocks[j].size > blocks[worstFitIndex].size)

worstFitIndex = j;

Operating System Lab(KCS-451) Prashant Yadav 2100910100131


}

if (worstFitIndex == -1) {

printf("Memory allocation failed for process %d. No suitable block found.\n", i + 1);

} else {

blocks[worstFitIndex].allocated = 1;

printf("Memory allocated successfully for process %d. Block size: %d\n", i + 1,


blocks[worstFitIndex].size);

int main() {

int numBlocks, numProcesses, i;

printf("Enter the number of memory blocks: ");

scanf("%d", &numBlocks);

struct Block blocks[MAX_BLOCKS];

printf("Enter the details of memory blocks:\n");

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

printf("Block %d size: ", i + 1);

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

blocks[i].allocated = 0;

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

scanf("%d", &numProcesses);

Operating System Lab(KCS-451) Prashant Yadav 2100910100131


int processSizes[MAX_PROCESSES];

printf("Enter the sizes of processes:\n");

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

printf("Process %d size: ", i + 1);

scanf("%d", &processSizes[i]);

allocateMemory(blocks, numBlocks, processSizes, numProcesses);

return 0;

OUTPUT

EXPERIMENT 6.2
Aim-: Implementation of contiguous allocation techniques.

Operating System Lab(KCS-451) Prashant Yadav 2100910100131


1. BEST FIT

PROGRAM
#include <stdio.h>

#define MAX_BLOCKS 100

#define MAX_PROCESSES 100

struct Block

int size;

int allocated;

};

void allocateMemory(struct Block blocks[], int numBlocks, int processSizes[], int numProcesses)

int i, j, bestFitIndex;

for (i = 0; i < numProcesses; i++)

bestFitIndex = -1;

for (j = 0; j < numBlocks; j++)

if (!blocks[j].allocated && blocks[j].size >= processSizes[i])

if (bestFitIndex == -1 || blocks[j].size < blocks[bestFitIndex].size)

bestFitIndex = j;

Operating System Lab(KCS-451) Prashant Yadav 2100910100131


}

if (bestFitIndex == -1)

printf("Memory allocation failed for process %d. No suitable block found.\n", i + 1);

} else

blocks[bestFitIndex].allocated = 1;

printf("Memory allocated successfully for process %d. Block size: %d\n", i + 1,


blocks[bestFitIndex].size);

int main()

int numBlocks, numProcesses, i;

printf("Enter the number of memory blocks: ");

scanf("%d", &numBlocks);

struct Block blocks[MAX_BLOCKS];

printf("Enter the details of memory blocks:\n");

for (i = 0; i < numBlocks; i++)

Operating System Lab(KCS-451) Prashant Yadav 2100910100131


printf("Block %d size: ", i + 1);

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

blocks[i].allocated = 0;

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

scanf("%d", &numProcesses);

int processSizes[MAX_PROCESSES];

printf("Enter the sizes of processes:\n");

for (i = 0; i < numProcesses; i++)

printf("Process %d size: ", i + 1);

scanf("%d", &processSizes[i]);

allocateMemory(blocks, numBlocks, processSizes, numProcesses);

return 0;

Operating System Lab(KCS-451) Prashant Yadav 2100910100131


OUTPUT

Operating System Lab(KCS-451) Prashant Yadav 2100910100131


EXPERIMENT 6.3
Aim-: Implementation of contiguous allocation techniques.
1. FIRST FIT

PROGRAM
#include <stdio.h>

#define MAX_BLOCKS 100

#define MAX_PROCESSES 100

struct Block

int size;

int allocated;

};

void allocateMemory(struct Block blocks[], int numBlocks, int processSizes[], int numProcesses)

int i, j;

for (i = 0; i < numProcesses; i++)

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

if (!blocks[j].allocated && blocks[j].size >= processSizes[i])

blocks[j].allocated = 1;

printf("Memory allocated successfully for process %d. Block size: %d\n", i + 1, blocks[j].size);

break;

Operating System Lab(KCS-451) Prashant Yadav 2100910100131


}

if (j == numBlocks)

printf("Memory allocation failed for process %d. No suitable block found.\n", i + 1);

int main()

int numBlocks, numProcesses, i;

printf("Enter the number of memory blocks: ");

scanf("%d", &numBlocks);

struct Block blocks[MAX_BLOCKS];

printf("Enter the details of memory blocks:\n");

for (i = 0; i < numBlocks; i++)

printf("Block %d size: ", i + 1);

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

blocks[i].allocated = 0;

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

Operating System Lab(KCS-451) Prashant Yadav 2100910100131


scanf("%d", &numProcesses);

int processSizes[MAX_PROCESSES];

printf("Enter the sizes of processes:\n");

for (i = 0; i < numProcesses; i++)

printf("Process %d size: ", i + 1);

scanf("%d", &processSizes[i]);

allocateMemory(blocks, numBlocks, processSizes, numProcesses);

return 0;

OUTPUT

Operating System Lab(KCS-451) Prashant Yadav 2100910100131

You might also like