Experiment two job scheduling simulation program (first come first service (FCFS) scheduling algorithm)

Source: Internet
Author: User

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.

III. analysis of simulation data results

1. The average turnaround time of each algorithm of the same simulation data is compared with the turnover coefficient.

2. (* *) using a graph or column chart to represent the above data, analysis of the advantages and disadvantages of the algorithm.

Iv. Other requirements

1. Complete report, complete content, specification.

2. The experiment must be examined to answer questions about the experiment.

Note: The entry with the * * number indicates the selection.

#include <stdio.h>#defineN 5structjcb{intName//Process Name    intAtime//Process Arrival Time    intRuntime//Process Run Time    intFtime;//Process Finish Time    intTotal//Turnaround Time    floatWelght;//weighted turnaround time (turnover factor)    intArun//Process arrives Run}f[n];//start execution time, time of completion of each job, turnaround time and time of ownership turnaround (turnover factor). voidMain () {intamount; inti,j,l,k,h; structJCB F[n]; printf ("Please enter the number of processes (2-24): \ n"); scanf ("%d",&amount);  for(i=0; i<amount;i++) {printf ("Please enter the process name, process arrival time (0-30), Process run time (1-8): \ n"); scanf ("%d",&f[i].name); scanf ("%d",&f[i].atime); scanf ("%d",&f[i].runtime); } printf ("process name \ t process arrival time \ t process run time \ n");  for(i=0; i<amount;i++) {printf ("%d\t%d\t\t%d\t\n", F[i].name,f[i].atime,f[i].runtime); } printf ("------First-come-first service (FCFS) scheduling algorithm------\ n");  for(i=0; i<amount-1; i++)//sequencing by process arrival time{//If two processes arrive at the same time, press ENTER first on the screen to run         for(j=i+1; j<amount;j++)        {             if(F[j].atime <f[i].atime) {L=F[j].atime; H=F[j].runtime; K=F[j].name; F[j].atime=F[i].atime; F[j].runtime=F[i].runtime; F[j].name=F[i].name; F[i].atime=l; F[i].runtime=h; F[i].name=K; }}} printf ("Order of arrival time by process \ n"); printf ("process name \ t process arrival time \ t process run time \ n");  for(i=0; i<amount;i++) {printf ("%d\t%d\t\t%d\t\n", F[i].name,f[i].atime,f[i].runtime); } printf ("Process name process reaches start run process run process end turnaround factor \ n"); f[0].arun=0;  for(i=0; i<amount;i++)    {        if(f[i].arun<f[i].atime) {F[i].arun=F[i].atime; } f[i].ftime=f[i].arun+F[i].runtime; F[i].total=f[i].ftime-F[i].atime; F[i].welght=(float) f[i].total/(float) F[i].runtime; printf ("%d\t%d\t%d\t%d\t%d\t\t%d\t%f\n", F[i].name,f[i].atime,f[i].arun,f[i].runtime,f[i].ftime,f[i].total,f[i].welght); F[i+1].arun=f[i].arun+F[i].ftime; } printf ("------Short Job First (SJF) scheduling algorithm------\ n");  for(i=1; i<amount;i++) { for(j=0; j<amount-i;j++) {if(f[j].runtime>f[j+1].runtime) {f[j].runtime+=f[j+1].runtime; F[j+1].runtime=f[j].runtime-f[j+1].runtime; F[j].runtime-=f[j+1].runtime; K=F[i].name; F[j].name=f[i+1].name; F[i+1].name =K; }}} for(i=0; i<amount;i++) {if(i==0) F[i].total=F[i].total; ElseF[i].total=f[i].runtime+f[i-1].ftime; F[i].ftime=f[i].atime+F[i].runtime; F[i].welght=(float) f[i].atime/(float) F[i].runtime; if(i==0) Prinf ("%d", F[i].name); Else{Prinf ("%d", F[i].name);  for(j=0; j<i;j++) {Prinf ("%d", F[j].name); } prinf ("*******"); }} printf ("Process name process reaches start run process run process end turnaround factor \ n");  for(i=0; i<amount;i++) {printf ("%d\t%d\t%d\t%d\t%d\t\t%d\t%f\n", F[i].name,f[i].atime,f[i].arun,f[i].runtime,f[i].ftime,f[i].total,f[i].welght); }}

Experiment two job scheduling simulation program (first come first service (FCFS) scheduling algorithm)

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.