zoukankan      html  css  js  c++  java
  • 时间片1

    #include<stdio.h>
    #define Time int
    #define M 100
    typedef struct process{
        char name[M];//进程名
        int priority;//优先数
        int reachtime;//到达时间
        int needtime;//需要时间
        int usedtime;//已用时间
        char state;//进程状态
        int Ptime;//时间片大小
    }PCB;      //进程控制块
    int n;
    PCB pcb[M];
    int pTime;
    void print(int n){
        int i;
        printf("#####################################进程调度###################################\n");
        printf("--------------------------------------------------------------------------------\n");
        printf("                  进程名\t优先数\t\t需要时间\t到达时间\n");
       for(i=0;i<n;i++){
        printf("                   %s\t\t%d\t\t%d\t\t%d\n",pcb[i].name,pcb[i].priority,pcb[i].needtime,pcb[i].reachtime);
        
       }
        printf("--------------------------------------------------------------------------------\n");
    }
    void sort(int n)
    {
        int i;
        PCB temp;
        int j;
        for(i=0;i<n;i++){//按优先数的高低排序
            for(j=i;j<n;j++){
         if(pcb[j].priority>pcb[i].priority)
         {
          temp=pcb[j];
         pcb[j]=pcb[i];
          pcb[i]=temp;

         }
         if(pcb[j].priority==pcb[i].priority)//优先数相等则按到达时间排序
         {
          if(pcb[j].reachtime<pcb[i].reachtime){
          temp=pcb[j];
          pcb[j]=pcb[i];
          pcb[i]=temp;
          }
            }
            }
        }
    }

        void main(){
        int i;
        int j;
        PCB temp;
        printf("请输入进程数:");
        scanf("%d",&n);
        for(i=0;i<n;i++){
            printf("\n请输入进程名:");
            scanf("%s",&pcb[i].name);
            printf("请输入优先数:");
            scanf("%d",&pcb[i].priority);
            printf("请输入需要的时间:");
            scanf("%d",&pcb[i].needtime);
            printf("请输入到达的时间:");
            scanf("%d",&pcb[i].reachtime);
        }

    sort(n);

    print(n);
    for(i=0;i<n;i++){
    while(pcb[i].needtime!=0){
    printf("\n请按任意键继续......\n");
    printf("\n");
    fflush(stdin);
    getchar();

    printf("                                       当前运行的程序是:\n");

    printf("--------------------------------------------------------------------------------\n");
    printf("                   进程名\t优先数\t\t需要时间\t到达时间\n");
    pcb[i].needtime=pcb[i].needtime-1;
    pcb[i].priority=pcb[i].priority-1;
     printf("                   %s\t\t%d\t\t%d\t\t%d\n",pcb[i].name,pcb[i].priority,pcb[i].needtime,pcb[i].reachtime);
    printf("--------------------------------------------------------------------------------\n");

    printf("\n");
    printf("\n");
    print(n);
    sort(n);

    }

    }

        printf("                             提示:时间片轮转调度结束!\n");


    }

  • 相关阅读:
    Ubuntu Linux Matlab 安装 中文乱码 桌面启动器 Could not find the main class: java/splash.png. 终端terminal 直接运行 matlab
    Ubuntu Linux 官网 u盘安装 u盘系统 图文教程
    从google map google earth获得大图 方法总结
    论文查重网址
    [ZZ] Computer Science Conference Rankings
    Ubuntu linux 信使 iptux Window 飞鸽 ipmsg 飞秋 feiq 文件传输
    Ubuntu Linux Matlab mex
    Ubuntu Dell OptiPlex 990 Intel Gigabit CT Desktop Adapter网卡驱动安装
    C++的File类文件操作
    GIS软件比较
  • 原文地址:https://www.cnblogs.com/hxhlo/p/5458386.html
Copyright © 2011-2022 走看看