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)