0% found this document useful (0 votes)
5 views3 pages

Priority Scheduling Algorithm in C

Uploaded by

alveenapbabu786
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)
5 views3 pages

Priority Scheduling Algorithm in C

Uploaded by

alveenapbabu786
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

/****************************************************************************/

Name : Donal Shaji Date : 26/03/2024


PRIORITY SCHEDULING
Roll No : 28 Experiment No : 12
/****************************************************************************/
PROGRAM
#include<stdio.h>
#include<string.h>

float avgwt, avgtt;


char pname[10][10];
int wt[10], tt[10], pri[10],bt[10], n, sum = 0, j, ss = 0, i;

int main() {
printf("Enter the number of processes:");
scanf("%d", &n);

printf("Enter the NAME, BURST TIME,PRIORITY of the process\n");

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


printf("\nPROCESS NAME: ");
scanf("%s", pname[i]);

printf("BURST TIME: ");


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

printf("PRIORITY: ");
scanf("%d", &pri[i]);
}

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


for (int j = i + 1; j < n; j++) {
if (pri[i] > pri[j]) {
int temp = bt[i];
bt[i] = bt[j];
bt[j] = temp;

temp = pri[i];
pri[i] = pri[j];
pri[j] = temp;

char tempStr[10];
strcpy(tempStr, pname[i]);
strcpy(pname[i], pname[j]);
strcpy(pname[j], tempStr);
}
}
}
wt[0] = 0;
sum = 0;
tt[0] = wt[0] + bt[0];
ss = tt[0];
for (i = 1; i < n; i++) {
tt[i] = tt[i - 1] + bt[i];
wt[i] = tt[i] - bt[i];
sum = sum + wt[i];
ss = ss + tt[i];
}

avgwt = (float)sum / n;
avgtt = (float)ss / n;
printf("\nPROCESS\t\tBURST TIME\tPRIORITY\tWAITING TIME\tTURNAROUND TIME\t");
for (i = 0; i < n; i++) {
printf("\n%s\t\t\t%d\t\t%d\t\t%d\t\t%d\t", pname[i], bt[i],pri[i], wt[i], tt[i]);
}
printf("\nAVG WAITING TIME=%f", avgwt);
printf("\nAVG TURN AROUND TIME=%f", avgtt);
printf("\nGANTT CHART PRIORITY SCHEDULING\n");

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


printf("|\t%s\t", pname[i]);
}
printf("|\n");
printf("0\t\t");
for (i = 0; i < n; i++) {
printf("%d\t\t", tt[i]);
}
return 0;
}
/****************************************************************************/
OUTPUT
Enter the number of processes:4
Enter the NAME, BURST TIME,PRIORITY of the process

PROCESS NAME: p1
BURST TIME: 7
PRIORITY: 2

PROCESS NAME: p2
BURST TIME: 3
PRIORITY: 3

PROCESS NAME: p3
BURST TIME: 1
PRIORITY: 0

PROCESS NAME: p4
BURST TIME: 9
PRIORITY: 1

PROCESS BURST TIME PRIORITY WAITING TIME TURNAROUND TIME


p3 1 0 0 1
p4 9 1 1 10
p1 7 2 10 17
p2 3 3 17 20

AVG WAITING TIME=7.000000


AVG TURN AROUND TIME=12.000000
GANTT CHART PRIORITY SCHEDULING

| p3 | p4 | p1 | p2 |
0 1 10 17 20
/****************************************************************************/

You might also like