Experiment two (Job scheduling)

Source: Internet
Author: User

#include <stdio.h>
#define N 24

typedef struct NODE
{
Char name[10]; /* Job Name */
int proc; Process priority number */
int arritime;//Arrival time
int starttime;//start time
int needtime; /* Process time required */
int RunTime; /* Run time */
int endtime;//End Time
int zztime;//Turnaround Time
float Zznum;
Char state; Status of the process */

/*struct node *next; Chain Pointer */
/*int round; Process time Rotation time slice */
/*int count; Counter */
}JCB;

int main (void) {
JCB Job[n];
int n;
void input ();
Input (job,&n);
void FCFS ();
FCFS (n);

}

void input (JCB job[],int N) {

int tot; Number of jobs
int i;

printf ("Please enter the number of jobs: [2-24]\n");
scanf ("%d", &tot);
for (i=0;i<tot;i++) {
Job[i].proc=i;
printf ("Enter the job name of the [i+1] job, arrival time, time required \ n");
scanf ("%s", &job[i].name);
scanf ("%d", &job[i]. Arritime);
scanf ("%d", &job[i]. Needtime);
scanf ("%d", &job[i]. EndTime);
scanf ("%d", &job[i]. Zztime);
scanf ("%4f", &job[i]. Zznum);
}
printf ("Time required for Job name arrival time \ n");
for (i=0;i<tot;i++)
{
printf ("%s", job[i].name);
printf ("%5d", Job[i]. Arritime);
printf ("%5d", Job[i]. Needtime);
printf ("%5d", Job[i]. EndTime);
printf ("%5d", Job[i]. Zztime);
printf ("%2.1f", Job[i]. Zznum);
}

}


void FCFS (int num)//First come first service algorithm calculation
{
int i,j;
for (i=0;i<num;i++)//sequential execution of jobs entering the queue
{if (i==0)//First process
{
Job[i]. Runtime=job[i]. Needtime;
Job[i]. Endtime=job[i]. Starttime+job[i]. RunTime;
}
Else
{
if (Job[i]. STARTTIME>JOB[I-1]. EndTime)//If there are currently jobs in the execution
{
Job[i]. Runtime=job[i]. Needtime;
Job[i]. Endtimejob[i]. Starttime+job[i]. RunTime;
}
Else
{
Job[i]. Runtime=job[i]. NEEDTIME+JOB[I-1]. Endtime-job[i]. StartTime;
Job[i]. Endtime=job[i]. Starttime+jobc[i]. RunTime;
}
}

(unfinishied)

Experiment two (Job scheduling)

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.