current position:Home>Short process first scheduling algorithm

Short process first scheduling algorithm

2022-01-26 22:02:30 Exposed wet dust

example < Two > Programming short process first scheduling algorithm

The specific implementation procedure is as follows :

#include<stdio.h>

#define n 5

#define num 5

#define max 65535

typedef struct pro

{

int PRO_ID;

int arrive_time;

int sum_time;

int flag;

}Pro;//l Integer sort

int bubble(int temp[])

{

int i,j,tem=0;

for(i=1;i<num;i++)

{

   int lastX=1;

for(j=0;j<num-i;j++)

{ if(temp[j]>temp[j+1])

{tem=temp[j];

temp[j]=temp[j+1];

temp[j+1]=tem;

lastX=0;

}

}

if(lastX==1) break;

}

return temp[0];

}

// Process sequencing

Pro bubble(Pro p[])

{

int i,j;

Pro temp={0};

Pro s[num];

for(i=0;i<num;i++)

{s[i]=p[i];

}

for(i=1;i<num;i++)

{

int lastX=1;

for(j=0;j<num-i;j++)

{

if(s[j].sum_time>s[j+1].sum_time)

{

temp=s[j];

s[j]=s[j+1];

s[j+1]=temp;

lastX=0;

}

}

if(lastX==1)break;

}

return s[0];

}

void SPF(int p)

{

if(n>0)

{

int i,j,k,l,tc=0;

Pro seq[n];

Pro temp_seq[n];

printf(" Short process priority scheduling algorithm SPFln");

printf(" Please input... In turn 5 The process number of a process 、 Arrival time and execution time n");printf(" Member variables are separated by commas ﹔ The processes are separated by carriage return \n");

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

scanf("%d,%d,%d",&seq[i].PRO_ID,&seq[i].arrive_time,&seq[i].sum_time);

}

printf(" The scheduling order is :\n");// initialization tc

int temp[num];

for(i=0;i<num;i++)

{

temp[i]=seq[i].arrive_time;

}

tc=bubble(temp);//tc It's a breakpoint

//flag Indicates correspondence i Of pro The queue situation

//-1 Indicates that you have not entered the queue ,0 Indicates that in the queue ,1 Indicates that it has been cleared

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

seq[i].flag=-1;

}

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

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

if(seq[i].flag!=1&&seq[i].arrive_time<=tc){

seq[j].flag=0;

}

}

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

temp_seq[j]=seq[j];

if(seq[j].flag!=0){

temp_seq[j].sum_time=max;

}

}

l=bubble(temp_seq).PRO_ID;

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

if(l==seq[j].PRO_ID){

k=j;

}

}

tc=tc+bubble(temp_seq).sum_time;

seq[k].flag=1;

printf("%d",l);

}

printf("\n");

}

}

void main()

{

SPF(n);

}

No error in execution :

Input 5 A process to test the program , The program results are as follows :

Four 、 Summary of the experiment

In this experiment, I learned Visual C++ 6.0 To realize the short process first service strategy in the process scheduling strategy of operating system course , In this experiment, I know that the advantage of this strategy is that it improves the average performance compared with the first come first serve strategy Turnaround time And the average Turnaround time with rights , Reduce job waiting time ; Improve system throughput ; In the final experimental results, the process 5 Has not been implemented , I can conclude that the disadvantage of this algorithm is that it is very disadvantageous to long jobs , May not be implemented for a long time ; And the priority of execution is not divided according to the urgency of the job ; It is difficult to estimate the work accurately ( process ) Execution time of , This will affect the scheduling performance .

copyright notice
author[Exposed wet dust],Please bring the original link to reprint, thank you.
https://en.cdmana.com/2022/01/202201262202275381.html

Random recommended