Shortest process first (shortest process FIRST,SPF) scheduling algorithm __ Operating system experiment

Source: Internet
Author: User

I. Purpose of the experiment
In batch processing system, time-sharing system and real time system, the number of processes is generally larger than the number of processors, which results in each process competing for the processor. This requires the process scheduler to follow the corresponding scheduling method and scheduling algorithm, from the many processes in the ready state to select a process to allocate the processor to it, so that the implementation.
This experiment uses high-level language to write and debug process scheduler, simulate process scheduling process, thus deepen understanding of process concept and process scheduling algorithm, and help students better understand the work of processor scheduling.

Ii. content of the experiment
1. The design has five process concurrent execution of the simulation scheduler, each program is represented by a PCB.
2. The simulation scheduler may choose two kinds of scheduling algorithm to realize.
3. The state of a variety of processes should be visible on the screen in the execution of the program.
4. Write the experiment report after the experiment.

Third, experimental methods
1. Algorithm design idea
The shortest process priority scheduling algorithm assigns the processor to the next "shortest CPU execution" process each time from the ready queue. I'm here. Every job that is more ready before the scheduling process is decided, select the job run with the shortest running time

2. The main data structure and function description of the program
The program uses the sort sort function in the C + + Standard Template Library, which customizes the compare comparison function and sorts the keyword from small to large by the arrival time of each job to find the first running job

3. Main modules
This experiment contains four modules, data input module, initial time to a process selection module, data processing calculation module, data output module, the most important is the data processing module, which not only realizes the data calculation function, It also enables you to select a job run with the shortest running time in a process that is already ready

Four, source program code

#include "iostream" #include "algorithm" using namespace std;
    struct node{string name;   Double arr;   Arrival time double ing;

Running time}ai[100];
    BOOL Compare (node A,node b) {if (A.arr==b.arr) return a.ing<b.ing;
Return a.arr<b.arr;
    int main () {int n;
    cout<< "Please enter the number of processes:";
    cin>>n;
    cout<< "Please enter" <<n<< "name of the process, arrival time, run Time" <<endl;
    for (int i=0;i<n;i++) {cin>>ai[i].name>>ai[i].arr>>ai[i].ing;
    Sort (ai,ai+n,compare);
    cout<< "process name \ t arrival time \ t run time \ Start time \ t end time \ Turnaround time \ Tape Power turnaround time" <<endl;
    Double Sta=ai[0].arr;
        for (int i=0;i<n;i++) {double jiesu=sta+ai[i].ing;
        Double Zhouz=jiesu-ai[i].arr;
        Double dzhouz=zhouz/ai[i].ing;
        cout<<endl;
        cout<<ai[i].name<< "T";
        cout<<ai[i].arr<< "\t\t";
        cout<<ai[i].ing<< "\t\t";
        cout<<sta<< "\t\t"; Cout<<jiesu<< "\t\t";
        cout<<zhouz<< "\t\t";

        cout<<dzhouz<<endl;
            if (i<n-2) {int mmax=i+1;
                for (int j=mmax+1;ai[j].arr<=jiesu&&j<n;j++) {if (ai[j].ing<ai[mmax].ing)
                {mmax=j;
            }}//cout<<mmax<<endl;
            Node Temp=ai[mmax];
            AI[MMAX]=AI[I+1];
        Ai[i+1]=temp;
    } sta=jiesu>ai[i+1].arr?jiesu:ai[i+1].arr; }
}

V. Results and analysis of program operation
1. Operating Results

2. Results analysis
Consistent with expected results, preliminary identification algorithm implementation

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.