Experiment two job scheduling simulation program

Source: Internet
Author: User

Experiment two job scheduling simulation program

Shizhengcheng 201306104124

I. Purpose and REQUIREMENTS

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.

Job scheduler for single-channel batch processing systems. When the job is put into operation, it occupies all the resources of the computer until the job is completed, so it is not necessary to schedule the job to consider whether the resources it needs are met, the time it runs, and so on.

Job scheduling algorithm:

1) The first-come-first service (FCFS) scheduling algorithm, that is, according to the order of operation arrived scheduling. The job that waits the longest in the system is always dispatched first.

2) Short job first (SJF) scheduling algorithm, priority scheduling requires the shortest running time of the job.

3) in response to high-priority (HRRN) scheduling algorithm, set a priority (response ratio) for each job, before scheduling to calculate the priority of each job, priority of the higher priority scheduling. RP (response ratio) = job turnaround time/job run time =1+ job wait time/job run time

Each job is represented by a job control block, JCB can include the following information: Job name, Submission (arrival) time, required run time, required resources, job status, chain pointers, and so on.

The status of the job can be one of waiting for W (wait), running R (run), and completing F (finish) three. The initial state of each job is to wait for W.

First, the generation of simulation data

1. Allows the user to specify the number of jobs (2-24) and the default value is 5.

2. Allows the user to choose to enter the arrival time and the desired run time for each job.

3. (* *) read the above data from the file.

4. (* *) also allows the user to choose a pseudo-random number to specify the arrival time (0-30) of each job and the desired run time (1-8).

Second, the function of the simulation program

1. 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).

2. Dynamic demonstration of each scheduling, update the current system time, in the running state and waiting for the corresponding information of each job (job name, arrival time, the desired run time, etc.) for the HRRN algorithm, can show each job response than R in each schedule.

3. (*) allows users to submit new jobs during the impersonation process.

4. (* *) to write and dispatch a multi-channel program system job scheduling simulation program. Only the job scheduling algorithm is required: the first-come-first service-based scheduling algorithm is used. For a multi-channel program system, it is assumed that the resource requirements for each job must be taken into account when scheduling jobs with various resources and quantities in the system.

Test methods, steps and Results

1. Flowchart

#include <stdio.h>#include<stdlib.h>#include<string.h>//defines the structure of a job scheduletypedefstructjcb{Charname[Ten]; CharState//status of the job    intarrive_t;//Arrival Time//int present_t;//Time of submission       intstart_t;//time to be preempted after running for a period of time       intfinish_t;//End Time       intneed_t;//Time to run       intzz_t;//Turnaround Time       intPriority//Priority Level       intactual_run_t;//Actual run time       Chardepend[Ten];//prerequisites for completion of the job       structJCB *next;//point to Next job}JCB;JCB job[ -],temp[ -];intTime=10000, N,flag;//Timer//Flag Flag Current job Remaining Amountvoidget_value ();voidPaixu (JCB jb[ -],intN) {       inti,j;  for(i=0; i<n;i++)       {               for(j=i+1; j<n;j++)                     if(job[i].arrive_t>job[j].arrive_t) {temp[i].arrive_t=job[i].arrive_t; job[i].arrive_t=job[j].arrive_t; job[j].arrive_t=temp[i].arrive_t; temp[i].need_t=job[i].need_t; job[i].need_t=job[j].need_t; job[j].need_t=temp[i].need_t;                         strcpy (Temp[j].name,job[i].name);                            strcpy (Job[i].name,job[j].name);                     strcpy (Job[j].name,temp[i].name); }       }}voidPAIXU1 (JCB jb[ -],intN) {       inti,j;  for(i=0; i<n;i++)       {               for(j=i+1; j<n;j++)                     if(job[i].need_t>job[j].need_t) {temp[i].arrive_t=job[i].arrive_t; job[i].arrive_t=job[j].arrive_t; job[j].arrive_t=temp[i].arrive_t; temp[i].need_t=job[i].need_t; job[i].need_t=job[j].need_t; job[j].need_t=temp[i].need_t;                         strcpy (Temp[j].name,job[i].name);                            strcpy (Job[i].name,job[j].name);                     strcpy (Job[j].name,temp[i].name); }}}fcfs (JCB job[ -],intN) {inti,j=0, now=0; JCB*P;flag=n;//number of remaining flag jobsPaixu (job,n);p rintf ("output sorted result: \ n"); for(i=0; i<n;i++) {printf ("%s\t%d\t%d\t", job[i].name,job[i].arrive_t,job[i].need_t);p rintf ("\ n");} for(i=0; i<n;i++) {p=&Job[i];if(p->arrive_t>Now ) now=p->arrive_t;if(p->state=='W'&&p->arrive_t<=Now ) {P->start_t=Now;now+=p->need_t;p->finish_t=now;p->zz_t=p->finish_t-p->arrive_t;p->state='F';} printf ("Job name arrival time Start time service time finish turnaround time \ n");p rintf ("%s%10d%10d%9d%10d%10d\n",p->name,p->arrive_t,p->start_t,p->need_t,p->finish_t,p->zz_t);}} SJF (JCB job[ -],intN) {       inti,j=0, now=0; JCB*P;flag=n;//number of remaining flag jobspaixu1 (job,n);p rintf ("output sorted result: \ n"); for(i=0; i<n;i++) {printf ("%s\t%d\t%d\t", job[i].name,job[i].arrive_t,job[i].need_t);p rintf ("\ n");} for(i=0; i<n;i++) {p=&Job[i];if(p->arrive_t>Now ) now=p->arrive_t;if(p->state=='W'&&p->arrive_t<=Now ) {P->start_t=Now;now+=p->need_t;p->finish_t=now;p->zz_t=p->finish_t-p->arrive_t;p->state='F';} printf ("Job name arrival time Start time service time finish turnaround time \ n");p rintf ("%s%10d%10d%9d%10d%10d\n",p->name,p->arrive_t,p->start_t,p->need_t,p->finish_t,p->zz_t);}} Prtf (JCB job[ -],intN) {paixu1 (job,n);} Run (intI//Select the appropriate module to start running{printf ("\n\n\n The virtual machine starts running: \ n"); Switch(i) { Case 1: Fcfs (Job, N); Break;  Case 2: SJF (Job, N); Break;  Case 3: Prtf (Job, N); Break; default: printf ("\ n Run Error! Please check the error!\n"); }}voidGet_value ()//get information about a process{       intnum; printf ("\ nthe total number of assignments? \ n"); scanf ("%d", &n);//n Indicates the number of jobsprintf ("\ n Enter information about the process:"); printf ("\nname\t arrive_t \ need_t\n");//Enter job name, time of arrival, time to run    for(num=0; num<n;num++) {scanf ("%s\t%d\t%d", &job[num].name,&job[num].arrive_t,&job[num].need_t);//Enter name, arrival time, run time   }    for(num=0; num<n;num++) {job[num].state='W';//status of the jobjob[num].actual_run_t=0;//actual run time of the job} printf ("Job Input Complete! \ n"); } main () {inti,flag1=0; printf ("Operating System Job Simulation Scheduler: \N\T1, FIFO scheduling \n\t2, short process priority scheduling \n\t2, maximum response than priority dispatch \ n"); printf ("Please select: \ n"); scanf ("%d",&i); if(i<1|| I>3) {Flag1=1; printf ("\ nthe input error, please enter a number between 1-3:"); }       Else{Flag1=0; }        while(flag)//re-enter if the number entered is not between 1-3{printf ("Please select: \ n"); scanf ("%d",&i); if(i<1|| I>3) {Flag1=1; printf ("\ nthe input error, please enter a number between 1-3:"); }            ElseFlag=0; } get_value ();//get basic information about a jobrun (i);//start running a job      }

3. Operation Results and analysis

This is the graph of the first-come-first service algorithm, which is a graph of the short process precedence algorithm

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.