Notes 241115 173837
Notes 241115 173837
h>
int i, n;
float tatAvg, wtAvg;
int main() {
int b[20];
printf("Number of Processes:");
scanf("%d", &n);
read(b);
calcTime(b);
return 0;
}
#include <stdio.h>
int i, j, n, pId[20];
float tatAvg, wtAvg;
void main() {
int b[20];
printf("Number of Processes:");
scanf("%d", &n);
read(b);
calcTime(b);
#include <stdio.h>
while (1)
{
/* Traverse */
int flag = 0;
void main()
{
int b[20], tat[20], wt[20];
printf("Number of Processes:");
scanf("%d", &n);
read(b);
printf("Enter time quantum:");
scanf("%d", &quantum);
calcTime(b, wt, tat);
}
#include <stdio.h>
int i, j, n;
float tatAvg, wtAvg;
struct Process {
int pId;
int bt;
int priority;
};
int main()
{
struct Process p[20]; /* Array object for the structure */
int wt[20], tat[20];
printf("Number of Processes:");
scanf("%d", &n);
read(p);
sort(p);
findWaitingTime(p, wt);
findTurnAroundtime(p, tat, wt);
display(p, wt, tat);
return 0;
#include <stdio.h>
int n, m;
void read(int alloc[][10], int max[][10], int avail[10], int need[][10], int n, int m);
void display(int temp[][10], int n, int m);
int safety(int alloc[][10], int avail[10], int need[][10], int n, int m);
int main()
{
int alloc[10][10], max[10][10], avail[10], need[10][10];
int i, j;
printf("Enter total number of processes: ");
scanf("%d", &n);
printf("Enter total number of resources: ");
scanf("%d", &m);
printf("\nProcess\tCurrently-Allocated-Resources\n");
display(alloc, n, m);
printf("\nProcess\tMaximum-Resources\n");
display(max, n, m);
printf("\nProcess\tPossibly-Needed-Resources\n");
display(need, n, m);
//Safety algorithm
int i, j, k, index = 0;
int isDone[10], sequence[10], count = 0; /* array to store safety sequence */
if (count != n) {
printf("\nDeadlock has occured.\n"); /* deadlock */
}
}
int main() {
int diskQueue[20], n, i, seekTime=0, diff;
printf("Enter the size of Queue: ");
scanf("%d", &n);
printf("Enter the Queue: ");
for(i=1;i<=n;i++) { /* head element to be read */
scanf("%d",&diskQueue[i]);
}
printf("Enter the initial head position: ");
scanf("%d", &diskQueue[0]); /* head element */
printf("\nMovement of Cylinders\n");
for(i=0;i<n;i++) {
diff= abs(diskQueue[i+1] - diskQueue[i]); /* abs( ) function in C returns the absolute
value of an integer, which is always positive. */
seekTime+= diff;
printf("Move from %d to %d with seek time %d\n", diskQueue[i], diskQueue[i+1], diff);
}
printf("\nTotal Seek Time: %d", seekTime);
printf("\nAverage Seek Time = %f",(float) seekTime/n);
printf("\n");
return 0;
}
#include <stdio.h>
int main()
{
int i, pCount, fCount, pages[30], frames[20];
printf("Number of Frames : ");
scanf("%d", &fCount);
// create frames array will null value
for (i = 0; i < fCount; ++i) {
frames[i] = -1;
}
printf("Number of Pages : ");
scanf("%d", &pCount);
printf("Enter the reference string\n");
for (i = 0; i < pCount; ++i) {
scanf("%d", &pages[i]);
}
// call the function
fifo(pages, frames, pCount, fCount);
return 0;
}
int main() {
int i, pCount, fCount, pages[30], frames[20], time[20];
printf("Number of Frames : ");
scanf("%d", &fCount);
// create frames array will null values
for (i = 0; i < fCount; ++i) {
frames[i] = -1;
}
printf("Number of Pages : ");
scanf("%d", &pCount);
printf("Enter the reference string\n");
for (i = 0; i < pCount; ++i) {
scanf("%d", &pages[i]);
}
LRU(pages, frames, time, fCount, pCount);
return 0;
}
void LRU(int pages[], int frames[], int time[], int fCount, int pCount) {
printf("\nRef.String |\tFrames\n");
printf("-------------------------------\n");