0% found this document useful (0 votes)
3 views2 pages

Os Lab Exp

Fjj

Uploaded by

aryansunil01
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Os Lab Exp

Fjj

Uploaded by

aryansunil01
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Fcfs Scheduling

#include <stdio.h>
int i, n; Sjf scheduling
float tatAvg, wtAvg; Round
#include <stdio.h> #include <stdio.h>
void read(int b[]) { int i, j, n, pId[20]; int i, n, quantum; /* give a time quantum
for (i = 0; i < n; ++i) { float tatAvg, wtAvg; */
printf("Enter the burst time of void swap(int *a, int *b) { void read(int b[]) {
process %d: ", i); int temp = *a; for (i = 0; i < n; ++i) {
scanf("%d", &b[i]); *a = *b; printf("Enter the burst time of
} *b = temp; process %d: ", i);
} } scanf("%d", &b[i]); } }
void sort(int b[]) { void findWaitingtime(int b[], int wt[]) {
void findWaitingtime(int b[], int wt[]) { int b_rem[20];
wt[0] = 0; for (i = 0; i < n - 1; ++i) { for (i = 0; i < n; ++i) {
int wtSum = 0; for (j = 0; j < n - 1 - i; ++j) { b_rem[i] = b[i];
for (i = 1; i < n; ++i) { if (b[j] > b[j + 1]) { }
wt[i] = wt[i - 1] + b[i - 1]; swap(&b[j], &b[j + 1]); int time = 0;
wtSum += wt[i]; swap(&pId[j], &pId[j + 1]); while (1)
} } {
wtAvg = (float)wtSum / n; } int flag = 0;
} } for (i = 0; i < n; ++i) {
} if (b_rem[i] > 0) {
void findTurnAroundtime(int tat[], int b[], void read(int b[]) { flag = 1;
int wt[]) { for (i = 0; i < n; ++i) { if (b_rem[i] > quantum) {
int tatSum = 0; printf("Enter the burst time of time += quantum;
for (i = 0; i < n; ++i) { process %d: ", i); b_rem[i] -= quantum;
tat[i] = b[i] + wt[i]; scanf("%d", &b[i]); }
tatSum += tat[i]; pId[i] = i + 1; /* process 1, process else {
} 2,... */ time += b_rem[i];
tatAvg = (float)tatSum / n; } wt[i] = time - b[i];
} sort(b); b_rem[i] = 0; }
} }
void display(int b[], int wt[], int tat[]) { void findWaitingtime(int b[], int wt[]) { }
printf("Process\tBurstTime wt[0] = 0; if (flag == 0) {
WaitingTime TurnAroundTime\n"); int wtSum = 0; break; }
for (i = 0; i < n; ++i) { for (i = 1; i < n; ++i) { }
printf("%d\t%d\t\t%d\t%d\n", i, b[i], wt[i] = wt[i - 1] + b[i - 1]; }
wt[i], tat[i]); wtSum += wt[i]; void findTurnAroundtime(int tat[], int b[],
} } int wt[]) {
printf("average waiting time: %f", wtAvg = (float)wtSum / n; for (i = 0; i < n; ++i) {
wtAvg); } tat[i] = b[i] + wt[i];
printf("\naverage turnaround time: %f", void findTurnAroundtime(int tat[], int b[], }
tatAvg); int wt[]) { }
printf("\n"); int tatSum = 0; void display(int b[], int wt[], int tat[]) {
} for (i = 0; i < n; ++i) { int wtSum = 0, tatSum = 0;
tat[i] = b[i] + wt[i]; printf("Process\tBurstTime
void calcTime(int b[]) { tatSum += tat[i]; } WaitingTime TurnAroundTime\n");
int wt[20], tat[20]; tatAvg = (float)tatSum / n; } for (i = 0; i < n; ++i) {
findWaitingtime(b, wt); void display(int b[], int wt[], int tat[]) { wtSum += wt[i];
findTurnAroundtime(tat, b, wt); printf("Process\tBurstTime tatSum += tat[i];
display(b, wt, tat); WaitingTime TurnAroundTime\n"); printf("%d\t%d\t\t%d\t%d\n", i, b[i],
} for (i = 0; i < n; ++i) { wt[i], tat[i]);
printf("%d\t%d\t\t%d\t%d\n", pId[i], }
int main() { b[i], wt[i], tat[i]); printf("average waiting time: %f",
} (float)wtSum / n);
int b[20]; printf("average waiting time: %f", printf("\naverage turnaround time: %f",
printf("Number of Processes:"); wtAvg); (float)tatSum / n);
scanf("%d", &n); printf("\naverage turnaround time: %f", printf("\n");
read(b); tatAvg); }
calcTime(b); printf("\n"); void calcTime(int b[], int wt[], int tat[]) {
} findWaitingtime(b, wt);
return 0; void calcTime(int b[]) { findTurnAroundtime(tat, b, wt);
} int wt[20], tat[20]; display(b, wt, tat);
findWaitingtime(b, wt); }
findTurnAroundtime(tat, b, wt); void main()
display(b, wt, tat); {
} int b[20], tat[20], wt[20];
void main() { printf("Number of Processes:");
int b[20]; scanf("%d", &n);
printf("Number of Processes:"); read(b);
scanf("%d", &n); printf("Enter time quantum:");
read(b); scanf("%d", &quantum);
calcTime(b); calcTime(b, wt, tat);
} }
printf("Number of Processes:");
scanf("%d", &n);
read(p);
sort(p);
findWaitingTime(p, wt);
Priority findTurnAroundtime(p, tat, wt);
#include <stdio.h> display(p, wt, tat);
int i, j, n; return 0;
float tatAvg, wtAvg; }
struct Process {
int pId;
int bt;
int priority;
};
void read(struct Process p[]) {
printf("\n");
for (i = 0; i < n; ++i) {
p[i].pId = i + 1;
printf("Enter the burst time for
process %d: ", p[i].pId);
scanf("%d", &p[i].bt);
printf("Enter the priority: ");
scanf("%d", &p[i].priority);
}
}
void display(struct Process p[], int wt[],
int tat[]) {
printf("\nProcessID | BurstTime |
Priority | Waiting time | Turn Around
Time\n");
for (i = 0; i < n; ++i) {
printf("%d\t\t%d\t%d\t\t%d\t\t%d\n",
p[i].pId, p[i].bt, p[i].priority, wt[i], tat[i]);
}
printf("average waiting time: %f",
wtAvg);
printf("\naverage turnaround time: %f",
tatAvg);
printf("\n");
}
void sort(struct Process p[]) {
struct Process temp;
for (i = 0; i < n - 1; ++i) {
for (j = 0; j < n - 1 - i; ++j) {
if (p[j].priority > p[j + 1].priority) {
temp = p[j];
p[j] = p[j + 1];
p[j + 1] = temp;
}
}
}
}
void findWaitingTime(struct Process p[],
int wt[]) {
wt[0] = 0;
int wtSum = 0;
for (i = 1; i < n; ++i) {
wt[i] = wt[i - 1] + p[i - 1].bt;
wtSum += wt[i];
}
wtAvg = (float)wtSum / n;
}
void findTurnAroundtime(struct Process
p[], int tat[], int wt[]) {
int tatSum = 0;
for (i = 0; i < n; ++i) {
tat[i] = p[i].bt + wt[i];
tatSum += tat[i];
}
tatAvg = (float)tatSum / n;
}
int main()
{
struct Process p[20];
int wt[20], tat[20];

You might also like