Os Exp
Os Exp
semaphore
Source Code:
#include <stdio.h>
#include <stdlib.h>
// Initialize a mutex to 1
int mutex = 1;
// Item produced
x++;
printf("\nProducer produces"
"item %d",
x);
// Driver Code
int main()
{
int n, i;
printf("\n1. Press 1 for Producer"
"\n2. Press 2 for Consumer"
"\n3. Press 3 for Exit");
// Switch Cases
switch (n) {
case 1:
case 2:
// Exit Condition
case 3:
exit(0);
break;
}
}
}
Output:
Write a program to demonstrate the concept of dynamic partitioning
placement algorithms Best Fit
Source Code:
// Driver Method
int main()
{
int blockSize[] = {100, 500, 200, 300, 600};
int processSize[] = {212, 417, 112, 426};
int m = sizeof(blockSize) / sizeof(blockSize[0]);
int n = sizeof(processSize) / sizeof(processSize[0]);
return 0 ;
}
Output:
Process No. Process Size Block no.
1 212 4
2 417 2
3 112 3
4 426 5
// Write a program to demonstrate the concept of dynamic partitioning
placement algorithms First Fit
#include<stdio.h>
// Driver code
int main()
{
int m; //number of blocks in the memory
int n; //number of processes in the input queue
int blockSize[] = {100, 500, 200, 300, 600};
int processSize[] = {212, 417, 112, 426};
m = sizeof(blockSize) / sizeof(blockSize[0]);
n = sizeof(processSize) / sizeof(processSize[0]);
return 0 ;
}
Output:
Source Code:
#include<stdio.h>
int main()
{
int i,j,n,a[50],frame[10],no,k,avail,count=0;
printf("\n ENTER THE NUMBER OF PAGES:\n");
scanf("%d",&n);
printf("\n");
}
printf("Page Fault Is %d",count);
return 0;
}
Output:
Page Fault Is 15
Write a program to demonstrate the concept of page replacement policies
for handling page faults LRU
Source Code:
#include<stdio.h>
#include<limits.h>
return 0;
}
int main()
{
int n = sizeof(incomingStream)/sizeof(incomingStream[0]);
int frames = 3;
int queue[n];
int distance[n];
int occupied = 0;
int pagefault = 0;
printFrame(queue, occupied);
}
else{
if(queue[j] == incomingStream[k])
break;
}
printf("\n");
}
return 0;
}
Output:
Page Frame1 Frame2 Frame3
1: 1
2: 1 2
3: 1 2 3
2: 1 2 3
1: 1 2 3
5: 1 2 5
2: 1 2 5
1: 1 2 5
6: 1 2 6
2: 1 2 6
5: 5 2 6
6: 5 2 6
3: 5 3 6
1: 1 3 6
3: 1 3 6
Page Fault: 8
Write a program in C to do disk scheduling - FCFS
Source Code:
#include<stdio.h>
#include<stdlib.h>
int main()
{
int RQ[100],i,n,TotalHeadMoment=0,initial;
printf("Enter the number of Requests\n");
scanf("%d",&n);
printf("Enter the Requests sequence\n");
for(i=0;i<n;i++)
scanf("%d",&RQ[i]);
printf("Enter initial head position\n");
scanf("%d",&initial);
for(i=0;i<n;i++)
{
TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-initial);
initial=RQ[i];
}
Output: