current position:Home>Different process scheduling algorithms

Different process scheduling algorithms

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

C++

One 、 The experiment purpose

  1. Understand the concept of process ;
  2. Learn to create process ;

3、 By using the first come first serve scheduling algorithm for several groups of data , Compare the advantages and disadvantages of the algorithm

Two . Experimental environment

C++

3、 ... and 、 The experimental steps

example < One > Programming first come first serve algorithm

The experimental code is as follows :

#include <iostream.h>

#define n 20

typedef struct

{

int id;

int atime;// Process arrival time

int runtime;// Process run time

}fcs;

void main()

{

int amount,i,j,diao,huan;

fcs f[n];

cout<<" Please enter the number of processes :"<<endl;

cin>>amount;

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

{

   cout<<" Please enter the process name , Process arrival time , Process run time :"<<endl;

   cin>>f[i].id;

   cin>>f[i].atime;

   cin>>f[i].runtime;

}

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

{

// Sort by process arrival time

// If two processes arrive at the same time , Press the first... Entered on the screen ü

   for(j=0;j<amount-i-1;j++)

   {

      if(f[j].atime>f[j+1].atime)

      {

          diao=f[j].atime;

          f[j].atime=f[j+1].atime;

          f[j+1].atime=diao;

          huan=f[j].id;

          f[j].id=f[j+1].id;

          f[j+1].id=huan;

}

}

}

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

{

   cout<<" process :"<<f[i].id<<" from "<<f[i].atime<<" Start "<<","<<" stay "<<f[i].atime+f[i].runtime<<" It's over ."<<endl;

   f[i+1].atime=f[i].atime+f[i].runtime;

}

}

No error in execution

The execution result is shown in the figure below :

 

Four 、 Summary of the experiment

In this experiment, I learned Visual C++ 6.0 Implement the first come first service strategy in the process scheduling strategy of operating system course , In this experiment, I know that the early ready process is in front of the ready queue , Processes that are late to be ready are at the end of the ready queue , First come, first served (FCFS) Always schedule the process at the top of the ready queue to the running state . That is to say , It only considers the order in which a process enters the ready queue , Instead of thinking about its next CPU Length of implementation cycle and other factors .FCFS The algorithm is simple and easy to operate , It's a non preemptive strategy , But the performance is not good .

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

Random recommended