Experiment two--simulating process scheduling in the CPU (first draft)

Source: Internet
Author: User

First, Experimental Purpose

This experiment can deepen the understanding of the concept of process control block and process queue.

Second, experimental content and requirements

1. Definition of the structure of the process PCB

2. Define the structure body

3. Enter the process sequence

4. Sort (by time in place)

5. Output process Run results

Third, Experiment Code and results test

1#include <stdio.h>2#include <stdlib.h>3 4 #defineWait 05 #defineRun 16 #defineMax 1007  8typedefstructpcb{9     CharName[max];Ten     intCPUTime; One     CharState ; A }PCB; -  - voidInput (PCB data[],intcount); the  - Main () { - PCB Data[max]; -     intcount; +printf"input The data number:"); -scanf"%d",&count); + input (data,count); A     return 0; at } -  - voidInput (PCB data[],intcount) { -     inti; -      for(i=0; i<count;i++){ -printf"input the%d name:\n". II1); inscanf"%s",&data[i].name);  -printf"input the%d time:\n", i+1); toscanf"%d",&data[i].cputime); +     } -      for(i=0; i<count;i++){ theData[i].state=wait; *     } $printf"The data are:\n");Panax Notoginsengprintf"name Usetime state\n"); -      for(i=0; i<count;i++){ theprintf"%10s%10d%5d\n", data[i].name,data[i].cputime,data[i].state); +     } A}

Experiment Summary:

VC is not very easy to use, the change in the body of the loop to save multiple times will cancel the error prompt;

Using the method of the array to write the need to leave a large memory;

Experiment two--simulating process scheduling in the CPU (first draft)

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.