• <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>

            TanZek's 技術(shù)空間

            勇往直前,專注于技術(shù)...

            首頁 新隨筆 聯(lián)系 聚合 管理
              7 Posts :: 19 Stories :: 13 Comments :: 0 Trackbacks
            1、進(jìn)程調(diào)度中多級反饋隊列調(diào)度算法的模擬實現(xiàn)
            Following The Source Code:
            ?1?#include?<queue>
            ?2?#include?<iostream>
            ?3?#include?<cstdlib>
            ?4?
            ?5?
            ?6?/*
            ?7?--------+?|Ready?Queue?1|?--------+?to?CPU
            ?8????__________________|
            ?9???+
            10?--------+?|Ready?Queue?2|?--------+?to?CPU
            11????__________________|
            12???+
            13?--------+?|Ready?Queue?3|?--------+?to?CPU
            14????__________________|
            15???+
            16?---------+?|Ready?Queue?4|?--------+?to?CPU
            17???+__________________|
            18?以上加號為進(jìn)程執(zhí)行流向
            19?*/
            20?
            21?int?time[4]={1,2,3,4};??//各個隊列的時間片?
            22?char?*str[4]={"first","second","third","fourth"};
            23?queue<int>?Rqueue[4];???//各個優(yōu)先級隊列定義?
            24?
            25?int?execu(int?n)???
            26?//n是指哪一個隊列?
            27?//proc假設(shè)為一個進(jìn)程?
            28?{
            29?????int?proc;???//代表一個進(jìn)程?
            30?????while(!Rqueue[n-1].empty())
            31?????{
            32?????????proc=Rqueue[n-1].front();?//取隊首進(jìn)程進(jìn)行調(diào)度?
            33?????????proc?=?proc?-?time[n-1];?//時間片輪轉(zhuǎn),執(zhí)行調(diào)度后得到的進(jìn)程?
            34?????????cout<<?proc?<<"?in?the?"<<str[n-1]<<"?queue"<<endl;???????????????
            35?????????if(?proc?>=0?)???//假設(shè)進(jìn)程時間片用完,但還沒有執(zhí)行完?
            36?????????{
            37???????????if(n-1<3)Rqueue[n].push(proc);?//將其壓入下一個低優(yōu)先級的隊列?
            38???????????else
            39?????????????Rqueue[n-1].push(proc);?//如果是最后一個隊列,則壓入本身?
            40?????????}
            41?????????Rqueue[n-1].pop();???????//進(jìn)行下一次隊列調(diào)度
            42?????}
            43?????return?0;??//返回,代表該隊列的所有進(jìn)程均已調(diào)度過?
            44?}
            45?
            46?int?schedule(int&?proc)?//最初執(zhí)行一個程序,創(chuàng)建一個進(jìn)程,調(diào)度算法開始?
            47?{
            48?????Rqueue[0].push(proc);???//將進(jìn)程壓入第一個隊列?
            49?????for(int?i=1;?i<=4;?i++)
            50?????execu(i);????
            51?????//當(dāng)execu()返回時,意味著上一優(yōu)先級隊列里的進(jìn)程均已調(diào)度完,進(jìn)行下一個隊列的調(diào)度?
            52?}
            53?
            54?
            55?int?main(int?argc,?char*?argv[])
            56?{
            57?/*
            58?????for(int?i=0;?i<100;?i++)
            59?????{
            60?????????int?n=int(rand())%4;????
            61?????????Rqueue[n].push(int(rand())%3);
            62?????}
            63?*/
            64?????int?proc=15;????????//新進(jìn)程
            65?????schedule(proc);?
            66?????system("PAUSE");
            67?????return?0;
            68?}
            69?

            以上即為我的實驗成果,經(jīng)編譯運(yùn)行后,證明是正確的。
            如果中間還有不正確的,請不吝指教。
            謝謝!
            posted on 2006-05-30 13:46 TanZek 閱讀(563) 評論(2)  編輯 收藏 引用 所屬分類: Subject-Study

            評論

            # re: 操作系統(tǒng)實驗(Operating System Experiment) 2007-06-19 10:46 李俊
            怎么運(yùn)行不了。大哥  回復(fù)  更多評論
              

            # re: 操作系統(tǒng)實驗(Operating System Experiment) 2007-06-19 10:47 李俊
            出現(xiàn)這樣的錯誤

            --------------------Configuration: 11 - Win32 Debug--------------------
            Compiling...
            11.cpp
            C:\Documents and Settings\Administrator\11.cpp(22) : error C2143: syntax error : missing ';' before '<'
            C:\Documents and Settings\Administrator\11.cpp(22) : error C2501: 'queue' : missing storage-class or type specifiers
            C:\Documents and Settings\Administrator\11.cpp(22) : error C2143: syntax error : missing ';' before '<'
            C:\Documents and Settings\Administrator\11.cpp(29) : error C2065: 'Rqueue' : undeclared identifier
            C:\Documents and Settings\Administrator\11.cpp(29) : error C2109: subscript requires array or pointer type
            C:\Documents and Settings\Administrator\11.cpp(29) : error C2228: left of '.empty' must have class/struct/union type
            C:\Documents and Settings\Administrator\11.cpp(29) : fatal error C1903: unable to recover from previous error(s); stopping compilation
            Error executing cl.exe.

            11.obj - 7 error(s), 0 warning(s)  回復(fù)  更多評論
              

            精品久久久无码21p发布| 久久精品国产亚洲综合色| 久久www免费人成看国产片| 99久久中文字幕| 日本福利片国产午夜久久| 狠狠色噜噜狠狠狠狠狠色综合久久| 久久天天躁狠狠躁夜夜网站 | 91久久精品国产成人久久| 99re久久精品国产首页2020| 99精品久久精品一区二区| 狠狠色丁香久久婷婷综| 精品久久久久久中文字幕| 99久久国产亚洲高清观看2024| 精品熟女少妇aⅴ免费久久| 久久影视综合亚洲| 中文无码久久精品| 九九久久99综合一区二区| 91亚洲国产成人久久精品| 性做久久久久久久久浪潮| 无遮挡粉嫩小泬久久久久久久| 精品久久久久中文字幕日本| 91久久精品国产成人久久| 亚洲人成无码久久电影网站| 色8久久人人97超碰香蕉987| 久久免费国产精品一区二区| 亚洲国产天堂久久综合| 国产婷婷成人久久Av免费高清| 国产精品无码久久四虎| 一本色道久久综合亚洲精品| 91久久精品91久久性色| 偷窥少妇久久久久久久久| 婷婷综合久久中文字幕| 午夜精品久久久久久| 激情伊人五月天久久综合| 欧美久久久久久| 99久久国产综合精品成人影院| 中文字幕久久精品无码| 亚洲伊人久久成综合人影院| 久久青青草原国产精品免费| 久久亚洲熟女cc98cm| 久久亚洲天堂|