0% found this document useful (0 votes)
10 views4 pages

Experiemnt 5

The document contains two experiments demonstrating scheduling concepts in process management. Experiment 5A illustrates non-preemptive scheduling with a C program that calculates waiting and turnaround times for processes. Experiment 5B showcases preemptive scheduling, using a time slice to manage process execution and compute average waiting and turnaround times.

Uploaded by

dakshmahajan2022
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)
10 views4 pages

Experiemnt 5

The document contains two experiments demonstrating scheduling concepts in process management. Experiment 5A illustrates non-preemptive scheduling with a C program that calculates waiting and turnaround times for processes. Experiment 5B showcases preemptive scheduling, using a time slice to manage process execution and compute average waiting and turnaround times.

Uploaded by

dakshmahajan2022
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/ 4

PROCESS MANAGEMENT:SCHEDULING

EXPERIMENT NO - 5A

AIM - Write a program to demonstrate the concept of non-preemptive scheduling .

#include <stdio.h>
int main() {
int bt[20], wt[20], tat[20], i, n;
float wtavg = 0.0, tatavg = 0.0;

printf("\nEnter the number of processes: ");


scanf("%d", &n);

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


printf("\nEnter Burst Time for Process %d: ", i + 1);
scanf("%d", &bt[i]);
}

wt[0] = 0;
tat[0] = bt[0];

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


wt[i] = wt[i - 1] + bt[i - 1]; tat[i] = tat[i - 1] + bt[i];
}

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


wtavg += wt[i];
tatavg += tat[i];
}

printf("\nPROCESS\tBURST TIME\tWAITING TIME\tTURNAROUND TIME\n");

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


printf("\nP%d\t\t%d\t\t%d\t\t%d", i + 1, bt[i], wt[i], tat[i]);
}

printf("\nAverage Waiting Time: %.2f", wtavg / n);


printf("\nAverage Turnaround Time: %.2f", tatavg / n);

return 0;}
PROCESS MANAGEMENT:SCHEDULING
EXPERIMENT NO - 5B

AIM - Write a program to demonstrate the concept of preemptive scheduling .

#include <stdio.h>
int main() {
int i, j, n, bu[10], wa[10], tat[10], t, ct[10], max;
float awt = 0.0, att = 0.0, temp = 0;

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


scanf("%d", &n);

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


printf("\nEnter Burst Time for Process %d: ", i + 1);
scanf("%d", &bu[i]);
ct[i] = bu[i];
}

printf("\nEnter the size of time slice: ");


scanf("%d", &t);

max = bu[0];
for(i = 1; i < n; i++) {
if(max < bu[i]) {
max = bu[i];
}
}

for(j = 0; j < (max / t) + 1; j++) {


for(i = 0; i < n; i++) {
if(bu[i] != 0) {
if(bu[i] <= t) {
tat[i] = temp + bu[i];
temp += bu[i];
bu[i] = 0;
} else {
bu[i] -= t;
temp += t;
}
}
}
}
for(i = 0; i < n; i++) {
wa[i] = tat[i] - ct[i]; // Waiting time = Turnaround time - Burst time
att += tat[i];
awt += wa[i]; }

printf("\nThe Average Turnaround Time is: %.2f", att / n);


printf("\nThe Average Waiting Time is: %.2f", awt / n);

printf("\nPROCESS\tBURST TIME\tWAITING TIME\tTURNAROUND TIME\n");

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


printf("\nP%d\t\t%d\t\t%d\t\t%d", i + 1, ct[i], wa[i], tat[i]);
}

return 0;
}

You might also like