• <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>
            我要啦免费统计
            實(shí)驗(yàn)室老是中毒,今天差點(diǎn)連代碼都保不住了
            貼貼備份
            進(jìn)程調(diào)度 實(shí)驗(yàn)一 RR 時(shí)間片輪轉(zhuǎn)


            #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{//調(diào)用進(jìn)程模塊
                char name[10];//進(jìn)程名
                char state; //進(jìn)程狀態(tài): 就緒,運(yùn)行,完成
                int super; //進(jìn)程優(yōu)先級
                int ntime;//需要運(yùn)行的時(shí)間
                int rtime;//到達(dá)時(shí)間 change
                struct pcb* link;//鏈接指針
            }
            *ready=null,*p;
            typedef 
            struct pcb PCB;
            void destroy();
            void check();

            void sort()//建立對進(jìn)程優(yōu)先級排列函數(shù)
            {
               PCB 
            *first,*second;
               
               
            int insert = 0;
               
               
            if( ( ready == null ) || ( ( p -> rtime ) < ( ready -> rtime ) ) ){//優(yōu)先級最大者,插入隊(duì)首
                    p -> link = ready;
                    ready 
            = p;
               }
             
               
            else {//進(jìn)程比較優(yōu)先級。插入適當(dāng)?shù)奈恢弥?/span>
                   first = ready;
                   second 
            = first -> link;
                   
            while( second != null){
                       
            if( (p -> rtime ) < (second -> rtime)){//come ing time
                       
            //插入當(dāng)前進(jìn)程前面
                           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 *** 當(dāng)前正在運(yùn)行的進(jì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 請輸入進(jìn)程數(shù)量");
                scanf(
            "%d",&num);
                
            for( i = 0;i < num; i++){
                  printf(
            " 進(jìn)程號No.%d",i);
                  p
            =getch(PCB);
                  printf(
            "\n 輸入進(jìn)程名:");
                  scanf(
            "%s",p->name);
                  printf(
            "\n 到達(dá)時(shí)間:");
                  scanf(
            "%d",&p->rtime);
                  printf(
            "\n 輸入進(jìn)程運(yùn)行時(shí)間:");
                  scanf(
            "%d",&p->ntime);
                  printf(
            "\n");
                  p 
            -> super =0; p -> state='W';
                  p 
            -> link = null;
                  sort();
            //調(diào)用函數(shù)
                }

            //    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()//建立進(jìn)程查看函數(shù)
            {
            //    PCB *pr;
               /*    printf("\n *** 當(dāng)前正在運(yùn)行的進(jìn)程:%s",p->name);顯示當(dāng)前 運(yùn)行 進(jìn)程
                disp(p);
            */

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

                
            return ;
            }


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


            /*void running()//進(jìn)程就緒函數(shù)
            {
                (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 按任意鍵繼續(xù).");
                    ch=getchar();
                    
                }
            */

                printf(
            "\n\n進(jìn)程已經(jīng)完成。\n");

                
                system(
            "pause");
                
            return 0;
            }

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

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

            沒有實(shí)現(xiàn) 搶占式 也沒有實(shí)現(xiàn)多級的
            有什么想法都可以 交流  回復(fù)  更多評論
              
            # re: 進(jìn)程調(diào)度 實(shí)驗(yàn)一 RR 時(shí)間片輪轉(zhuǎn)算法 (記錄) 2008-11-12 13:15 | 飄過
            用最小堆做個(gè)多優(yōu)先級的也是個(gè)不錯(cuò)的選擇,不必非用鏈表,怪麻煩的  回復(fù)  更多評論
              
            # re: 進(jìn)程調(diào)度 實(shí)驗(yàn)一 RR 時(shí)間片輪轉(zhuǎn)算法 (記錄) 2008-11-12 20:54 | cdy20
            @飄過
            也是

            當(dāng)練手的,兩年沒用過指針了。  回復(fù)  更多評論
              

            只有注冊用戶登錄后才能發(fā)表評論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            久久综合综合久久综合| 国产成人久久精品二区三区| 久久婷婷午色综合夜啪| 亚洲欧洲精品成人久久曰影片| 国色天香久久久久久久小说| 国产精品禁18久久久夂久 | 久久精品无码一区二区无码| 精品精品国产自在久久高清| 久久综合亚洲色HEZYO国产 | 久久久噜噜噜久久中文福利| 久久国产乱子伦精品免费强| 国产精品久久久香蕉| 久久91精品国产91久久麻豆| 亚洲精品高清一二区久久| 久久精品成人免费看| 久久综合亚洲鲁鲁五月天| 久久国产精品99精品国产987| 久久天天躁狠狠躁夜夜2020 | 国内精品久久久久久久97牛牛| 国产精品久久国产精品99盘 | 狠色狠色狠狠色综合久久| 久久久精品人妻一区二区三区蜜桃 | 久久综合久久综合久久| 狠狠色噜噜狠狠狠狠狠色综合久久| 品成人欧美大片久久国产欧美 | 国产亚洲综合久久系列| 久久婷婷五月综合国产尤物app| 亚洲国产精品无码成人片久久| 色综合久久88色综合天天| 久久人人爽人人爽人人片av高请| 久久91精品综合国产首页| 久久天堂电影网| 9191精品国产免费久久| 91久久精品国产91性色也| 久久久综合九色合综国产| 久久99精品久久久久久久不卡| 青青草原综合久久大伊人导航| 97精品久久天干天天天按摩| 欧美噜噜久久久XXX| 精品无码久久久久久午夜| 久久亚洲日韩精品一区二区三区|