Experimental three-process scheduling simulation program
Major: Internet of things project name: Huang No.:201306104145
First, the purpose and requirements of the experiment
Objective:
A process scheduler is completed in a high-level language to deepen the understanding of process concepts and process scheduling algorithms.
Experimental requirements
Design a process scheduling simulator with n(n not less than 5) processes executing concurrently.
Process scheduling algorithm:" Time slice rotation method " scheduling algorithm to N processes.
Ii. contents of the experiment
The design, coding and debugging of two algorithms (Simple time slice rotation method and multistage feedback queue scheduling algorithm ) are completed, and the experimental report is completed.
1) Each process has a Process control block ( PCB cpu  
2) r ( ready r ( running f ( finished ) one of three states.
3) The ready process can only run one time slice after acquiring the CPU. Represented by the elapsed CPU time plus 1 .
4) If the elapsed CPU time of the process has reached the required run time after running a time slice , then the process is undone if the elapsed CPU of the process is run after a time slice Time has not reached the required run time, that is, the process needs to continue to run, it should be inserted into the ready queue to wait for the next dispatch.
5) Each time the schedule is scheduled , the program prints a run process, the PCB of each process in the ready queue forinspection.
6) Repeat the process until the process is complete.
Three, the experimental principle and the core algorithm:
The " rotation method " has the simple rotation method and the multilevel feedback queue scheduling algorithm.
(1). The basic idea of the simple rotation method is:
All ready processes are queued as FCFS , always assigning the processor to the team's first process, with the same length of time slices for each process that consumes the CPU . If the running process has not finished using its time slice, send it back to the end of the ready queue and reassign the processor to the team's first process. Until all processes have finished running.
(2). The basic idea of the multilevel feedback queue scheduling algorithm is:
Divide the ready queue into n -level (n=3~5), Each ready queue has a different priority and is assigned to a different time slice: the higher the queue level, the lower the priority number, the longer the time slice, and the lower the priority, the shorter the time slice.
The system is scheduled from the first level, when the first level is empty, the system turns to the second level queue,... when the running process runs out of time slices, if not done then discard CPU and go to the next level queue.
When the process is first ready, it enters the first-level queue.
Four, the experimental environment
Choose the experimental environment independently. Turbo C can be chosen as the development environment. You can also choose a visual environment under Windows to make it easier to take advantage of a variety of controls.
Test methods, steps and Results
1. SOURCE program Name: Compressed package file (RAR or Zip) source program name HM.C
Executable program name:hm.exe
2. principle Analysis and Flowchart
The use of arrays to store functions , in the previous job scheduling based on the change.
3. main procedural paragraphs and their explanations:
#include <stdio.h>
#include <string.h>
#include <conio.h>
#include <stdlib.h>
int i,k,num,m,n;
#define N 25
struct jcb{
Char name[10]; Process Name
float at; Arrival Time
float RT; Run Time
float S; Start Time
float F; Time to complete
float CT; CPU time used
Char status[25]; Status
float p; Priority Level
}jcb[n],temp;
void input ()// user Input module
{
int i;
do{
printf ("\ n Please enter the number of jobs (3-24):");
scanf ("%d", &num);
printf ("\ n");
if (num<3| | NUM>24)
{
printf (" input error, please re-enter!") \ n ");
}
}
while (num<3| | NUM>24);
for (i=0;i<num;i++)
{
strcpy (Jcb[i].status, "R"); The state of all processes is waiting before scheduling
printf (" %d job name :", i+1);
scanf ("%s", &jcb[i].name);
printf ("\ n commit time :");
scanf ("%f", &jcb[i]. at);
printf ("\ n run time :");
scanf ("%f", &jcb[i]. RT);
printf ("\ n");
}
}
void output ()// Output Module
{
printf ("*************************************\n");
printf (" Job name arrival time elapsed CPU time \ n");
for (i=0;i<num;i++)
{
printf ("%-9s%-9.0f%-9.0f%-10.0f%\n", Jcb[i].name,jcb[i]. At,jcb[i]. Rt,jcb[i]. CT);
}
printf ("*************************************\n");
}
void simple ()// Easy Rotation Method
{
int time=1,m=0,ge=0; Time stands for
int i,j;
int a[25];
while (1)
{
for (j=0;j<num;j++)
{
if (Jcb[j]. At>=time)// Judging how many jobs arrived at that time
{
A[m]=j;
m++;
}
}
for (i=0;i<m;i++)// per m for One loop
{
if (strcmp (Jcb[a[i]].status, "F") ==0) continue;// has been dispatched, it does not need to be dispatched
Else Jcb[a[i]]. ct++; CPU time plus one
if (Jcb[a[i]]. Ct==jcb[a[i]]. RT)// If the process uses CPU time equal to run time, then its status is complete.
strcpy (Jcb[a[i]].status, "F");
time++;
Output ();
}
for (i=0;i<num;i++)// Determine if all schedules are complete then exit while
{
if (strcmp (Jcb[a[i]].status, "F") ==0) ge++;
if (ge==num) break;
}
if (ge==num) break;
}
}
Main ()
{
int n;
do{
Input ();
printf (" Process Scheduler simulator \ n");
printf ("0:exit quit \ n \ nthe");
scanf ("%d", &n);
printf ("\ n");
if (n==0) continue;
else simple ();
}
while (n!=0);
}
4. operation results and Analysis
Input module:
Operation Result:
Vi. Summary of the experiment
Would have to write multi-level feedback queue scheduling, but will not write, only write a simple rotation method, and realize the algorithm and show the results of the process, still need to progress.
Experimental three-process scheduling simulation program