Experimental three-process scheduling simulation program

Source: Internet
Author: User

1.Purpose and requirements

1.1. Purpose of the experiment

A process scheduler is completed in a high-level language to deepen the understanding of process concepts and process scheduling algorithms.

1.2. Experimental Requirements

Design a process scheduling simulator with n processes executing concurrently.

Process scheduling algorithm: Using the highest priority scheduling algorithm (that is, the processor is assigned to the highest priority process) and first-come first service (if the same priority) algorithm.

(1). Each process has a Process Control block (PCB) representation. The Process Control block contains the following information: Process name, priority, arrival time, required run time, elapsed CPU time, process state, and so on.

(2). The priority of the process and the desired run time can be specified in advance, and the running time of the process is calculated in time slices.

(3). The state of each process can be either ready, running R (Running), or completing one of the three states of F (finished).

(4). The ready process can only run one time slice after the CPU is acquired. Represented by the elapsed CPU time plus.

(5). If the elapsed CPU time of a process has reached the desired run time after a time slice is run, the process is undone, and if the elapsed CPU time of the process after running a time slice has not reached the required run time, that is, the process needs to continue running, the priority number of the process should be reduced by 1 (that is, lowering the first , and then insert it into the ready queue for scheduling.

(6). Each time the scheduler is run, the PCB for each process in the running process and ready queue is printed for inspection.

(7). Repeat the process until the process is complete.

3. Experiment principle and core algorithm reference program segment

#include <stdio.h>#include<string.h>#defineN 100structpcb{Charname[Ten]; intPriority ; intReqtime; intruntime; intstatus;}; PCB A[n];voidPaixu (intN,PCB A[n]); main () {intN,i; printf ("Please enter the number of processes:"); scanf ("%d",&N);  for(i=0; i<n;i++) {printf ("Name:"); scanf ("%s",&a[i].name); printf ("Priority :"); scanf ("%d",&a[i].priority); printf ("Reqtime:"); scanf ("%d",&a[i].reqtime);    } Paixu (N,a); printf ("name Priority Reqtime Runtime status\n");  for(i=0; i<n;i++) {printf ("%s %d%d%d%d\n", A[i].name,a[i].priority,a[i].reqtime,a[i].runtime,a[i].status); }     while(i=1) {printf ("%s%d%d\n", a[0].name,a[0].priority,a[0].reqtime); a[0].priority=a[0].priority-1;        Paixu (N,a); if(a[0].priority==0) Break; }}//SortvoidPaixu (intN,PCB A[n]) {    intI,j,y; CharK[n];  for(i=0; i<n;i++)     for(j=i+1; j<n;j++)    {        if(a[j].priority>a[i].priority) {y=a[j].priority; A[j].priority=a[i].priority; A[i].priority=y; Y=A[j].reqtime; A[j].reqtime=A[i].reqtime; A[i].reqtime=y;            strcpy (K,a[j].name);            strcpy (A[j].name,a[i].name);        strcpy (A[I].NAME,K); }    }}

4. Summary

Still do not do, on the basic familiar, to go into the scheduling of those who will not how, hand can, but to become code will not Le, the best can refer to the code of the teacher.

Experimental three-process 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.