• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            我要啦免费统计
            實驗室老是中毒,今天差點連代碼都保不住了
            貼貼備份
            進程調度 實驗一 RR 時間片輪轉


            #include
            <stdio.h>
            #include
            <stdlib.h>
            #include
            <conio.h>
            #include
            <iostream>
            using namespace std;

            #define getch(type)(type*)malloc(sizeof(type))
            #define null 0
            #define MAXN 1000
            int stack[MAXN];
            int top;

            struct pcb{//調用進程模塊
                char name[10];//進程名
                char state; //進程狀態: 就緒,運行,完成
                int super; //進程優先級
                int ntime;//需要運行的時間
                int rtime;//到達時間 change
                struct pcb* link;//鏈接指針
            }
            *ready=null,*p;
            typedef 
            struct pcb PCB;
            void destroy();
            void check();

            void sort()//建立對進程優先級排列函數
            {
               PCB 
            *first,*second;
               
               
            int insert = 0;
               
               
            if( ( ready == null ) || ( ( p -> rtime ) < ( ready -> rtime ) ) ){//優先級最大者,插入隊首
                    p -> link = ready;
                    ready 
            = p;
               }
             
               
            else {//進程比較優先級。插入適當的位置中
                   first = ready;
                   second 
            = first -> link;
                   
            while( second != null){
                       
            if( (p -> rtime ) < (second -> rtime)){//come ing time
                       
            //插入當前進程前面
                           p -> link = second;
                           first 
            -> link = p;
                           second 
            = null;
                           insert 
            = 1;   
                        
                           }

                        
            else{
                             first 
            = first -> link;
                             second 
            = second -> link;
                           }

                       
                    }

                   
            if( insert == 0) first -> link =p;

               
               }

               
            return ;
            }


            PCB 
            *q;
            PCB 
            *front,*rear;

            void RR()
            {
                
            int time=0;
                q
            =ready;
                front
            =ready;
                rear 
            =ready;
                
            while(rear->link != null) rear= rear -> link; 
                
                
            while( front){
                    printf(
            "Running Time : %d\n",++time);

                    
            if(front -> rtime <= time){
                       
                         front 
            -> state ='R';

                        front 
            -> ntime--;//need time minus 1

                        printf(
            "\n *** 當前正在運行的進程:%s\n",front->name);

                        
            if( front -> ntime == 0){// the one which is finished
                        p = front;

                        
            if(front -> link !=null )
                        front 
            =front ->link;
                        
            else {printf("\n finished\n");break;}


                        p 
            -> link = null;

                        destroy();

                        }

                        
            else{//else unfinished ,connect last

                        rear 
            -> link = front;

                        p
            =front;
                        
            if(front -> link !=null )
                        front 
            =front ->link;
                        
            else {printf("\n finished\n");break;}

                        p 
            -> link = null
                        }

                    
                     check();
            //display all pcbs in queue
                   }

                 
                }

                
            return ;
            }


            void input()
            {
                
            int i,num;
                system(
            "cls");
                
            //clrscr();
                printf("\n 請輸入進程數量");
                scanf(
            "%d",&num);
                
            for( i = 0;i < num; i++){
                  printf(
            " 進程號No.%d",i);
                  p
            =getch(PCB);
                  printf(
            "\n 輸入進程名:");
                  scanf(
            "%s",p->name);
                  printf(
            "\n 到達時間:");
                  scanf(
            "%d",&p->rtime);
                  printf(
            "\n 輸入進程運行時間:");
                  scanf(
            "%d",&p->ntime);
                  printf(
            "\n");
                  p 
            -> super =0; p -> state='W';
                  p 
            -> link = null;
                  sort();
            //調用函數
                }

            //    check();
                return;
            }


            int space()
            {
                
            int l=0;
                PCB 
            *pr=ready;
                
            while(pr != null){
                 l
            ++;
                 pr 
            = pr->link;
                }

                
            return l;

            }


            void disp(PCB *pr)
            {
                printf(
            "\n qname\t state \t super \t ntime \t rtime\n");
                printf(
            "| %s\t",pr->name);
                printf(
            "| %c\t",pr->state);
                printf(
            "| %d\t",pr->super);
                printf(
            "| %d\t",pr->ntime);
                printf(
            "| %d\t",pr->rtime);
                printf(
            "\n");
             
            return ;
            }

            void check()//建立進程查看函數
            {
            //    PCB *pr;
               /*    printf("\n *** 當前正在運行的進程:%s",p->name);顯示當前 運行 進程
                disp(p);
            */

                p
            =front;
                printf(
            "\n ****當前就緒隊列狀態:%c",p->state);/* 顯示隊列狀態 */ 
                
            while( p != null){
                 disp(p);
                 p
            =p->link;
                }

                
            return ;
            }


            void destroy()/*建立進程撤銷 函數 (進程 運行結束,撤銷進程)*/
            {
                printf(
            "\n 進程[%s]已完成。\n",p->name);
                free(p);
                
            return;
            }


            /*void running()//進程就緒函數
            {
                (p->rtime)++;
                if( p-> rtime == p -> ntime)// 
                    destroy();
                else{
                  (p->super)--;
                  
                  p->state = 'W';
                  
                  sort();
                }
                return;
            }
            */

            int main()
            {
               freopen(
            "in.txt","r",stdin);
                
            int len,h=0;
            //    char ch;
                input();
                len
            =space();
                RR();
            /*    while((len != 0) && ( ready !=null)){
                    ch=getchar();
                    h++;
                    printf("\n The execute number :%d\n",h);
                    p= ready;
                    ready = p->link;
                    p->link=null;//吧最前的拿出來 
                    p->state ='R';
                    check();
                    running();
                    // system("pause");
                    printf("\n 按任意鍵繼續.");
                    ch=getchar();
                    
                }
            */

                printf(
            "\n\n進程已經完成。\n");

                
                system(
            "pause");
                
            return 0;
            }

            posted on 2008-11-05 20:43 閱讀(4264) 評論(5)  編輯 收藏 引用

            評論:
            # re: 進程調度 實驗一 RR 時間片輪轉算法 (記錄)[未登錄] 2008-11-06 09:26 | raof01
            標題很吸引人,內容很讓人失望。  回復  更多評論
              
            # re: 進程調度 實驗一 RR 時間片輪轉算法 (記錄) 2008-11-06 10:01 | PDF閱讀器下載
            個人覺得代碼還是不錯的  回復  更多評論
              
            # re: 進程調度 實驗一 RR 時間片輪轉算法 (記錄)[未登錄] 2008-11-06 19:58 | cdy20
            為了應付 老師堂上檢查
            不過要怎么改都行的 ,畢竟模擬

            沒有實現 搶占式 也沒有實現多級的
            有什么想法都可以 交流  回復  更多評論
              
            # re: 進程調度 實驗一 RR 時間片輪轉算法 (記錄) 2008-11-12 13:15 | 飄過
            用最小堆做個多優先級的也是個不錯的選擇,不必非用鏈表,怪麻煩的  回復  更多評論
              
            # re: 進程調度 實驗一 RR 時間片輪轉算法 (記錄) 2008-11-12 20:54 | cdy20
            @飄過
            也是

            當練手的,兩年沒用過指針了。  回復  更多評論
              
            久久国产成人精品国产成人亚洲| 久久免费视频1| 久久精品免费全国观看国产| 99久久亚洲综合精品网站| 91精品国产高清久久久久久io | 久久精品国产亚洲AV香蕉| 合区精品久久久中文字幕一区| 久久有码中文字幕| 久久精品免费一区二区三区| 久久久久精品国产亚洲AV无码| 精品久久久久久久久免费影院| 久久精品综合一区二区三区| 久久影院久久香蕉国产线看观看| 亚洲国产日韩欧美综合久久| 亚洲人成网亚洲欧洲无码久久| 久久精品国产免费观看| 久久天天躁狠狠躁夜夜不卡| 久久精品国产精品亚洲毛片| 亚洲精品高清国产一久久| 久久中文字幕精品| 久久久久久亚洲Av无码精品专口| 热99re久久国超精品首页| 久久综合成人网| 久久精品国产2020| 久久久精品午夜免费不卡| 久久夜色精品国产亚洲| 久久午夜电影网| 亚洲一区精品伊人久久伊人 | 国产亚洲精品久久久久秋霞 | 久久精品三级视频| 综合久久精品色| 亚洲AV成人无码久久精品老人| 狠狠色伊人久久精品综合网| 久久精品国产亚洲AV蜜臀色欲| 久久久精品国产| 久久不射电影网| 久久天天躁夜夜躁狠狠躁2022| 久久精品国产精品亚洲人人| 精品无码久久久久久尤物| 2021国内精品久久久久久影院| 久久狠狠一本精品综合网|