1. Purpose and Requirements
Experimental purpose
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.
2. Experimental content
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) representation. The Process Control block contains the following information: Process name, priority, arrival time, required run time, elapsed CPU time, process state, and so on.
2) The status of each process can be either ready, running R (Running), or completing one of the three states of F (finished).
3) The ready process can only run one time slice after acquiring the CPU. Represented by the elapsed CPU time plus.
4) If the elapsed CPU time of the process has reached the desired run time after a time slice is run, the process is undone, and if the elapsed CPU time of the process after running a time slice has not reached the required run time, that is, the process needs to continue running, it should be inserted into the ready queue 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 for inspection.
6) Repeat the process until the process is complete.
3. Experiment Code
#include <stdio.h>
typedef struct jcb{
Char name[10];
Char state;
int tt; Arrival time
int kt; Start time
int JT; End time
int NT; Time to run
int ZZT; Turnaround time
int DDT; Wait time
int Staut; State
}PCB;
PCB WORK[10],WORK1[10],WORK2[10];
int n,now,i,j;
static int maxnt;
int number=1;
Getit ()
{
int num,aaa=0;
printf ("\ nthe total number of jobs?") ");
scanf ("%d", &n);
printf ("\ n now please enter details for each process: \ n");
printf ("Time required for process name arrival time \ n");
for (aaa=0;aaa<n;aaa++)
{
scanf ("%s", &work[aaa].name);
scanf ("%d", &work[aaa].tt);
scanf ("%d", &work[aaa].nt);
}
printf ("input completed; \ n");
printf ("The information you have entered is: \ n");
printf ("Time required for process name arrival time \ n");
for (num=0;num<n;num++)
{
printf ("%s\t%d\t%d\t\n", Work[num].name,work[num].tt,work[num].nt);
}
}
Max ()
{
PCB temp;
for (i=0;i<10;i++)
{
Work1[i]=work[i];
Work2[i]=work[i];
}
for (i=0;i<n;i++)
{
for (j=i+1;j<n;j++)
{
if (Work[j].nt>work[i].nt)
{
TEMP=WORK1[J];
Work1[j]=work1[i];
Work1[i]=temp;
}
}
}
Maxnt=work1[0].nt;
}
Paidui ()
{
int i,j;
PCB temp;
for (i=0;i<n;i++)
{
for (j=i+1;j<n;j++)
{
if (WORK[J].TT<WORK[I].TT)
{
TEMP=WORK[J];
Work[j]=work[i];
Work[i]=temp;
}
}
}
for (i=0;i<n;i++)
{
work[i].state=1;
}
}
Simple ()
{
int a=1,i,j;
Now=work[0].tt;
for (j=0;j<maxnt;j++)
{
printf ("%d rotations:", number);
number++;
for (i=0;i<n;i++)
{
if (work[i].tt<=now&&work[i].state==1)
{
Work[i].nt=work[i].nt-a;
if (work[i].nt==0)
work[i].state=0;
Now=work[i].tt+number;
printf ("%s\t", work[i].name);
}
}
printf ("\ n");
}
}
Much ()
{
int A=1,i,j,key=1;
Now=work[0].tt;
for (J=0;j<maxnt;j=j+a-1)
{
printf ("%d rotations:", number);
number++;
for (i=0;i<n;i++)
{
if (work[i].state==1)
{
Work[i].nt=work[i].nt-a;
if (work[i].nt<=0)
work[i].state=0;
Now=work[i].tt+a;
printf ("%s\t", work[i].name);
}
}
a=a+1;
printf ("\ n");
}
}
Select ()
{
int i;
printf ("\ n-------------------------Good Life starts here!------------------------\ n");
printf ("Operating system job Simulation Scheduler: \N\N\T1, Simple time slice rotation method \n\n\t2, multilevel feedback queue scheduling algorithm \ n");
printf ("Please select: \ n");
scanf ("%d", &i);
if (i==1)
{
printf ("\ n you selected a simple time slice rotation \ n");
Getit ();
Paidui ();
Max ();
Simple ();
}
if (i==2)
{
printf ("\ n you have selected a multilevel feedback queue scheduling algorithm \ n");
Getit ();
Paidui ();
Max ();
Much ();
}
if (i>3)
{
printf ("\ n input error, please enter a number between 1-2!\n start again: \ n");
}
}
void Main ()
{
Select ();
}
4 Experience
Further understanding of the content of process scheduling.
Experimental three-process scheduling simulation program