zoukankan      html  css  js  c++  java
  • 实验二——模拟在CPU中的进程调度(改稿)

    一、        实验目的

    通过本实验可以加深对有关进程控制块、进程队列的概念的进一步理解。

    二、        实验内容和要求

         1.进程PCB的结构体定义

         2.定义结构体

         3.输入进程序列

         4.排序(按到位时间)

         5.输出进程运行的结果

    三、        实验代码及结果测试

     1 #include<stdio.h>
     2 #include<stdlib.h>
     3 
     4 #define wait 0
     5 #define run 1
     6 #define max 1000
     7  
     8 typedef struct pcb{
     9     char name[max];
    10     int cputime;
    11     char state;
    12 }pcb;
    13 
    14 void input(pcb data[],int count);
    15 void output(pcb data[],int count);
    16 
    17 main(){
    18     pcb data[max];
    19     int count;
    20     printf("input the data number:");
    21     scanf("%d",&count);
    22     input(data,count);
    23     output(data,count);
    24     return 0;
    25 }
    26 
    27 void input(pcb data[],int count){
    28     int i;
    29     for(i=0;i<count;i++){
    30         printf("input the %d name:
    ",i+1);
    31         scanf("%s",&data[i].name);        
    32         printf("input the %d time:
    ",i+1);
    33         scanf("%d",&data[i].cputime);
    34     }
    35     for(i=0;i<count;i++){
    36         data[i].state=wait;
    37     }
    38     printf("the data are:
    ");
    39     printf("   name     usetime     state
    ");
    40     for(i=0;i<count;i++){
    41         printf("%10s %10d %5d
    ",data[i].name,data[i].cputime,data[i].state);
    42     }
    43 }
    44 
    45 void output(pcb data[],int count){
    46     int i;
    47     int j;
    48     pcb temp;
    49     for(i=0;i<count-1;i++){
    50         for(j=i+1;j<count;j++){
    51             if(data[j].cputime<data[i].cputime)
    52             {
    53                 temp=data[j];
    54                 data[j]=data[i];
    55                 data[i]=temp;
    56             }
    57         }
    58     }
    59     printf("the work is:
    ");
    60     for(i=0;i<count;i++)
    61     {
    62         printf("%10s %10d %5d
    ",data[i].name,data[i].cputime,data[i].state);
    63     }
    64 }

    总结:

    已对模拟的进程进行使用时间的排序;

    尚未对进程的优先级排序;

  • 相关阅读:
    MSSQL大量数据时,建立索引或添加字段后保存更改超时该这么办
    POJ 3261 Milk Patterns (后缀数组)
    POJ 1743 Musical Theme (后缀数组)
    HDU 1496 Equations (HASH)
    694. Distinct Substrings (后缀数组)
    POJ 1222 EXTENDED LIGHTS OUT (枚举 或者 高斯消元)
    POJ 1681· Painter's Problem (位压缩 或 高斯消元)
    POJ 1054 The Troublesome Frog (hash散列)
    HDU 1716 排列2
    HDU 4405 Aeroplane chess (概率DP & 期望)
  • 原文地址:https://www.cnblogs.com/murasame/p/5448282.html
Copyright © 2011-2022 走看看