} ///////////////////////////////////////////////////////////////////////////////////// // // 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(); // 隨機生成第一個進程的ID,以后生成的進程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調用 只是模擬,我給進程設定了自己的語法,輸入一般的字符cpu調用時只是正常輸出,假如碰到' 表示該進程要調用系統資源后面必須跟一個數字表示占有的時間,假如資源閑置則占有資源否則阻塞,等資源釋放在占有資源。進程的調用算法我采用的是時間片輪轉算法并有所改進,當某個進程從阻塞隊列釋放后,他將把以前因為等待資源而被浪費的時間補回來。 希望大家多提意見