Monday, December 26, 2011

Exercise Program - 5.a IMPLEMENTATION OF PRIORITY SCHEDULING ALGORITHM

AIM:

To write a C program for implementing the priority scheduling using Linux operating system.

ALGORITHM:

Step 1: Start the program.

Step 2: Declare the variables as required.

Step 3: Get the number of process.

Step 4: Get the burst time for each process.

Step 5: get the ID value for each process.

Step 6: Get the arrival time for each process.

Step 7: Using the read data find the waiting time and turnaround time and average turn around

time and print the result.

Step 8: Stop the program.

PROGRAM:

#include

#include

typedef struct pcb

{

int pid, bt, bt_bal, tat, wt, prty;

} PCB;

int main()

{

PCB pr[10], temp;

int i,j,k,n,tq;

int sum_bt=0,sum_tat=0,sum_wt=0;

int gantt[3][50];

printf("\nPriority Scheduling \n\n");

printf("\nEnter the no. of process : ");

scanf("%d",&n);

for(i=0;i

{

printf("\nEnter burst time and priority of the process %d: ",i+1);

pr[i].pid = i+1;

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

}

for( i=0; i

for(j=i+1; j

if( pr[i].prty > pr[j].prty )

{

temp = pr[i];

pr[i] = pr[j];

pr[j] = temp;

}

k=0;

for( i=0;i

{

sum_bt += pr[i].bt;

pr[i].tat = sum_bt;

pr[i].wt = pr[i].tat - pr[i].bt;

sum_wt += pr[i].wt;

sum_tat += pr[i].tat;

gantt[0][k] = pr[i].pid;

gantt[1][k] = sum_bt;

gantt[2][k] = sum_bt - pr[i].bt;

k++;

}

printf("\nPriority Scheduling \n\n");

printf("PID: ");

for( i=0; i

printf("%4d",pr[i].pid);

printf("\nBTime:");

for( i=0; i

printf("%4d",pr[i].bt);

printf("\nPrty :");

for( i=0; i

printf("%4d",pr[i].prty);

printf("\n\nGANTT Chart\n\n");

printf("PID: ");

for( i=0; i

printf("%4d",gantt[0][i]);

printf("\nTime: ");

for( i=0; i

printf("%4d",gantt[1][i]);

printf("\n\nWTime:");

for( i=0; i

printf("%4d",gantt[2][i]);

printf("\n\nTotal waiting time = %d\n",sum_wt);

printf("Average waiting time = %.2f\n",(float)sum_wt/n);

printf("\nTotal turn around time = %d\n",sum_tat);

printf("Average turn around time = %.2f\n\n",(float)sum_tat/n);

return 0;

}

SAMPLE OUTPUT:

[it65@AntiViruS ~]$ cc priority.c

[it65@AntiViruS ~]$ ./a.out

Priority Scheduling

Enter the no. of process : 5

Enter burst time and priority of the process 1: 10 3

Enter burst time and priority of the process 2: 1 1

Enter burst time and priority of the process 3: 2 4

Enter burst time and priority of the process 4: 1 5

Enter burst time and priority of the process 5: 5 2

Priority Scheduling

PID: 2 5 1 3 4

BTime: 1 5 10 2 1

Prty : 1 2 3 4 5

GANTT Chart

PID: 2 5 1 3 4

Time: 1 6 16 18 19

WTime: 0 1 6 16 18

Total waiting time = 41

Average waiting time = 8.20

Total turn around time = 60

Average turn around time = 12.00


RESULT:

Thus the C program for implementing priority scheduling has been executed and the output is verified successfully.

1 comment:

Amanat said...

sir for loops are incomplete
so before posting the programs please check once