Get the App
SLTechnology News&Howtos  ›  Development  › 

How to dynamically simulate the process scheduling algorithm of operating system by Java

Shulou Source: shulou.com Published: 2022-06-02 09:06:03 09月27日 Update

This article mainly explains "how Java dynamically simulates the process scheduling algorithm of the operating system". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how Java dynamically simulates the process scheduling algorithm of the operating system.

Experimental purpose

Through the simulation of the process scheduling algorithm, we can further understand the basic concepts of the process, and deepen the understanding of the running state of the process, the process scheduling process and the scheduling algorithm.

Equipment and environment

Hardware equipment: one PC

Software environment: install the Windows operating system, and install the relevant program development environment, such as C\ C++\ Java programming language environment.

Content of the experiment

In the experiment, java language is used to simulate N processes using dynamic high priority process scheduling algorithm. The algorithm runs the process according to the size of the priority. If it is not finished in a time slice, the priority number is subtracted by 3 and then inserted into the linked list to sort in the order of priority to find the largest priority as the next running process and the process priority in the ready queue will be added by 1.

Main module:

Dynamic priority sorting module:

Used to ensure that the head is always the largest.

The arrival time enters the ready state module:

Calculate turnaround time and weighted turnaround time:

Experimental results and analysis

Information entered

The initial weights are all 100 minutes and the required time is still needed.

Process arrival time service time

A03

B26

C44

D65

E82

Take An as an example:

At the end of the day:

Part of the code shows / / create the structure class PCB {time of the String ID; int priority=-1; int cputime;// service time required by the int needtime;// 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 }} to determine whether the process arrives or not, the process enters for (int iready.priority) {/ / if this node priority is greater than the header priority pcb.next=ready; ready=pcb;} else {boolean false; tmp=ready / / Q while (m==false) {if (tail.priority > = pcb.priority) {/ / insert tail tail.next=pcb; tail=pcb; pcb.next=null; m=true } else {if (tmp.priority > = pcb.priority&&pcb.priority > tail.priority) {/ / gradually traverse pcb.next=tmp.next; tmp.next=pcb; masked truth before inserting it into tmp;} else {tmp=tmp.next At this point, I believe you have a deeper understanding of "how Java dynamically simulates the process scheduling algorithm of the operating system". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Process time algorithm scheduling dynamic operating system system environment experiment run content module sort maximum priority state node device language turnover Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL macOS NVidia Shulou Tech Info OPPO Reno