} ///////////////////////////////////////////////////////////////////////////////////// // // The main progress // ///////////////////////////////////////////////////////////////////////////////////// void main() { int num; cout<<" ********************************************************"<<endl <<endl; cout<<" The virtual CPU the process runned "<<endl
cout<<"initialize the information of processes "<<endl; cout<<"Please input the number of process [#command#] >/ "; try
catch(int) { cout<<"You input the numbers of process is error !"<<endl; exit(1); } Process::RandID(); // 隨機(jī)生成第一個(gè)進(jìn)程的ID,以后生成的進(jìn)程ID順序加1 CPU virtualCPU(num);
cout<<"Pocesses runed by CPU "<<endl; virtualCPU.Run();
cout<<"Processes runned over ! "<<endl; cout<<" ********************************************************"<<endl <<endl; cout<<" The time which processes runned by CPU : "<<virtualCPU.getAlltime()<<endl <<endl; virtualCPU.displayPro(); cout<<" *******************************************************"<<endl <<endl; }這里沒有任何的API調(diào)用 只是模擬,我給進(jìn)程設(shè)定了自己的語(yǔ)法,輸入一般的字符cpu調(diào)用時(shí)只是正常輸出,假如碰到' 表示該進(jìn)程要調(diào)用系統(tǒng)資源后面必須跟一個(gè)數(shù)字表示占有的時(shí)間,假如資源閑置則占有資源否則阻塞,等資源釋放在占有資源。進(jìn)程的調(diào)用算法我采用的是時(shí)間片輪轉(zhuǎn)算法并有所改進(jìn),當(dāng)某個(gè)進(jìn)程從阻塞隊(duì)列釋放后,他將把以前因?yàn)榈却Y源而被浪費(fèi)的時(shí)間補(bǔ)回來(lái)。 希望大家多提意見