1202 experimental three-process scheduling experiment

Source: Internet
Author: User

First, the purpose of the experiment

A process scheduler is completed in a high-level language to deepen the understanding of process concepts and process scheduling algorithms.

Second, the contents and requirements of the experiment

1. 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. Complete the design, coding and debugging of two algorithms (Simple time slice rotation method, multistage feedback queue scheduling algorithm), complete the experiment report.

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.

Test methods, steps and Results

1. SOURCE program Name: Compressed package file (RAR or Zip) source program name 3.c

Executable Program Name: 3.exe

2. Principle Analysis and flowchart

This program is mainly for the use of process scheduling algorithm, the main program is the menu () function call, the menu () function in the while (1), so that it is continuously executed to achieve the effect of experimental requirements.

3. Main procedural paragraphs and their explanations:

#include <stdio.h>
typedef struct jcb{
Char name[10];
Char state;
int arrivetime; Arrival time
int runtime; Time to run
int Staut; State
}PCB;

PCB WORK[10],WORK1[10],WORK2[10];
int a,n,now,i,j;
static int maxruntime;
int number=1;
Input ()
{
int num,aaa=0;

printf ("\ nthe total number of jobs?") ");
scanf ("%d", &n);
printf ("\ n Please enter the time required for process name arrival time for each process: \ n");
for (aaa=0;aaa<n;aaa++)
{
scanf ("%s", &work[aaa].name);
scanf ("%d", &work[aaa].arrivetime);
scanf ("%d", &work[aaa].runtime);
}
printf ("entered information: \ n");
printf ("Time required for process name arrival time \ n");
for (num=0;num<n;num++)
{
printf ("\t%s\t%d\t%d\t\n", work[num].name,work[num].arrivetime,work[num].runtime);
}
}

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].runtime>work[i].runtime)
{
TEMP=WORK1[J];
Work1[j]=work1[i];
Work1[i]=temp;

}
}
}
Maxruntime=work1[0].runtime;
}
Paidui ()
{
int i,j;
PCB temp;
for (i=0;i<n;i++)
{
for (j=i+1;j<n;j++)
{
if (work[j].arrivetime<work[i].arrivetime)
{
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].arrivetime;
for (j=0;j<maxruntime;j++)
{
printf ("%d rotations:", number);
number++;
for (i=0;i<n;i++)
{
if (work[i].arrivetime<=now&&work[i].state==1)
{
Work[i].runtime=work[i].runtime-a;
if (work[i].runtime==0)
work[i].state=0;
Now=work[i].arrivetime+number;
printf ("%s\t", work[i].name);
}
}
printf ("\ n");
}
menu ();
}
Much ()
{
int a=1,i;
Now=work[0].arrivetime;
for (j=0;j<maxruntime;j=j+a-2)
{
printf ("%d rotations:", number);
number++;
for (i=0;i<n;i++)
{
if (work[i].state==1)
{
Work[i].runtime=work[i].runtime-a;
if (work[i].runtime<=0)
work[i].state=0;
Now=work[i].arrivetime+a;
printf ("%s\t", work[i].name);
}
}
a=a+1;
printf ("\ n");
}
}
Menu ()
{
int i;
printf ("\ n------------------------------------Welcome to use!----------------------------------\ n");
printf ("Process Scheduler: \N\N\T1, Simple time slice rotation method \n\n\t2, multistage feedback queue scheduling algorithm \N\N\T3 exit program \ n");
printf ("Please select: \ n");
scanf ("%d", &i);
System ("CLS");//Clear screen
if (i==1)
{
printf ("\ n you selected a simple time slice rotation \ n");
Input ();
Paidui ();
Max ();
Simple ();
}
else if (i==2)
{
printf ("\ n you have selected a multilevel feedback queue scheduling algorithm \ n");
Input ();
Paidui ();
Max ();
Much ();
}
else if (i==3)
{
printf ("Quit the program, thank you for using!");
Exit (0);
}
else if (i>3)
{
printf ("\ n input error, please reenter: (1 or 2) \ n");
}
}
void Main ()
{
while (1)
{
menu ();
}
}

4. Operation Result and analysis

Run the program, has the following effect: At this time you can choose the option, choose to enter the simple time slice runner method, select 2--into the multilevel feedback queue scheduling algorithm, select 3--Exit program.

Select 1 to enter the interface:

At this point, you can enter the number of jobs, and then prompt "Please enter the time required for each process name arrival time:", after entering the input information and the runner situation, and then again prompted to select the option.

Select 2 to enter the interface.

The specific operation and effect can refer to the case of selecting 1.

Select 3 to Prompt "Quit the program, thank you for using!"

Iv. Summary of the experiment

Because not familiar with the time slice rotation method and the multilevel feedback queue scheduling algorithm, writes the procedure the time first the approximate frame, later passes the net to check the data and asks schoolmate to know the algorithm formula, the algorithm part is later adds to. Part of the program is still some problems, hope that after review can improve the program, so that the program more idealized.

1202 experimental three-process scheduling experiment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.