1112 experiment two job scheduling simulation program

Source: Internet
Author: User


First, the purpose of the experiment

1. Purpose of the experiment

(1) Deepen the understanding of the job scheduling algorithm;

(2) Training in program design.

2. Experimental requirements

A simulation program that writes one or more job schedules in a high-level language. According to the arrival time and required running time of the simulated data, the FCFS, SJF and HRRN scheduling algorithms are executed, the program calculates the start execution time of each job, the completion time of each job, the turnaround time and the turnaround time (turnover factor).

Ii. contents of the experiment

Complete the design, coding and commissioning work according to the assigned experimental project and complete the experiment report.

Test methods, steps and Results

    1. source program name 1.c; executable program name: 1.exe

2. Principle Analysis and flowchart

The structure of a process is defined first, including the process name, arrival time, execution time, start time, finish time, turnaround time. Then let the customer enter, then enter the algorithm to be used, and then the system shows the results of the algorithm run out.

3. Main procedural paragraphs and their explanations:

Main () {    struct stu S[max];    int i,j,p;    printf ("Number of input processes:");    scanf ("%d", &n);    for (i=0;i<n;i++)    {        getchar ();        printf ("Enter the name of the process of the first%d:", i+1);        scanf ("%c", &s[i].name);        printf ("Enter the arrival time of the%d process:", i+1);        scanf ("%d", &s[i].gettime);        printf ("Enter the execution time for%d processes:", i+1);        scanf ("%d", &s[i].time);        s[i].kstime=0;        s[i].wctime=0;        s[i].zztime=0;    }    printf ("            name  gettime  time  kstime  wctime  zztime\n");    for (j=0;j<n;j++)    {    printf ("Jinchen      %c%d%d%d%d       %d\n", s[j].name,s [J].gettime,s[j].time,s[j].kstime,s[j].wctime,s[j].zztime);    }    while (1)    {    printf ("Select the algorithm to use: 1,FCFS;2,SJF;3,HRRF:");    scanf ("%d", &p);    Switch (p)    {case    1:        FCFS (s);        break;    Case 2:        SJF (s);        break;    Case 3:        HRRF (s);        Break;}}}    
void Fcfs (struct Stu d[]) {    int i,j,q; struct Stu Tim; for (i=  0;i<n- 1;i++ "{ for (j=i+  1;j <n;j++) { if (D[i].gettime>d[j].gettime) {tim=d[i]; d[i]=d[j]; d[j]=tim;} }} Q=d[0].gettime; for (i=0;i<n;i++) {if (q<d[i].gettime) q=d[i].gettime; d[i].kstime=q; d[i].wctime=q+d[i].time; D[i].zztime=d[i] . wctime-d[i].gettime; Q=q+d[i].wctime; } printf ("The following is the dispatch result of FCFS: \ n"); printf ("Name gettime time kstime wctime zztime\n"); for (j=0;j<n;j++) {printf ("Jinchen%c%d%d%d%d%d\n", d[j].name,d[j].gettime,d[j].time,d[j].kstime,d[j].wctime,d[ J].zztime); }}
 void Sjf (struct stu d[]) {int i,j,q;    struct Stu Tim;    Q=d[0].gettime;                for (i=0;i<n-1;i++) {for (j=i+1;j<n;j++) {if (d[j].gettime<=q) {                    if (d[i].time>d[j].time) {tim=d[i];                    D[I]=D[J];                D[j]=tim;    }} Q=q+d[i].time;    } q=d[0].gettime;        for (i=0;i<n;i++) {if (q<d[i].gettime) q=d[i].gettime;        d[i].kstime=q;        D[i].wctime=q+d[i].time;        D[i].zztime=d[i].wctime-d[i].gettime;    Q=q+d[i].wctime;    } printf ("The following is the dispatch result of SJF: \ n");    printf ("Name gettime time kstime wctime zztime\n"); for (j=0;j<n;j++) {printf ("Jinchen%c%d%d%d%d%d\n", d[j].name,d[j].gettime,d[    J].time,d[j].kstime,d[j].wctime,d[j].zztime); }}

Iv. Summary of the experiment

through this experiment, I learned a lot of knowledge , deepened the understanding of the job scheduling algorithm, consulted some information and asked the students to get the answer, overall very challenging

1112 experiment two job scheduling simulation program

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.