“This is the 22nd day of my participation in the Gwen Challenge in November. Check out the details: The Last Gwen Challenge in 2021.”

takeaway

PS: Recently, a lot of small partners asked me how to prepare for the algorithm competition and interview questions, and some new students do not know how to learn programming, fat to prepare some columns for everyone interested can go to see oh!

Well today we have prepared the final comprehensive experiment of manipulation system for your reference! The source code is available on my home page.

I. Purpose of the experiment

Through the simulation of the process scheduling algorithm, the basic concept of the process is further understood, and the understanding of the process running state, process scheduling process and scheduling algorithm is deepened.

Ii. Equipment and environment

  1. Hardware: one PC
  2. Software environment: Install Windows operating system, and install the relevant program development environment, such as C++, Java and other programming language environment.

3. Experiment content

The experiment uses Java language programming to simulate N processes using dynamic high-priority scheduling algorithm. In this algorithm, processes are run according to the size of priority. If the priority weight is not finished in a time slice, the priority weight is reduced by 3 and then inserted into the linked list in order of priority to find the largest priority as the next running process and the priority of the process in the ready queue will be increased by 1.

The main module:

Dynamic Priority ordering module: used to ensure that the header is always the largest

Arrival time enters ready state module:

Calculate turnaround time and turnaround time with weights:

4. Experimental results and analysis

The input information has an initial weight of 100 and needTime is the service time of the process arrival time

A	0	3
B	2	6
C	4	4
D	6	5
E	8	2
Copy the code

Take A as an example:

At the end:

Part of code display

// Create the structure
class PCB{
    String ID;
    int priority=-1;
    int cputime;// Service time
    int needtime;// The time required by the process
    String state="wait";
    int arrivetime;
    PCB next;
    public PCB(String ID,int priority,int cputime,int arrivetime){
        this.ID=ID;
        this.priority=priority;
        this.cputime=cputime;
        this.arrivetime=arrivetime; }}Copy the code
Determines whether or not the process enters the timefor(int i=0; i<arr.size(); i++){if(h==arr.get(i).arrivetime){ Dynamic_priority.sort(arr.get(i)); arr.remove(i); }}Copy the code
// Put the process into ready state and sort it
public static void sort(PCB pcb){
PCB tmp=null;
        if(ready==null) {// The header is nullready=pcb; tail=pcb; }else {if(pcb.priority>ready.priority){// If this node priority is greater than header prioritypcb.next=ready; ready=pcb; }else {
               boolean m=false;
               tmp=ready;//q
               while (m==false) {if(tail.priority>=pcb.priority){// Insert the tail
                       tail.next=pcb;
                       tail=pcb;
                       pcb.next=null;
                       m=true; }
                   else {
                       if(tmp.priority>=pcb.priority&&pcb.priority>tail.priority){// gradually traverse to TMP
                           pcb.next=tmp.next;
                           tmp.next=pcb;
                           m=true;
                       } else { tmp=tmp.next;
Copy the code