- 相關(guān)推薦
操作系統(tǒng)課程設(shè)計(jì)報(bào)告模擬進(jìn)程調(diào)度程序(一)
此設(shè)計(jì)報(bào)告是對(duì)操作系統(tǒng)中進(jìn)程調(diào)度的兩種算法,即靜態(tài)優(yōu)先權(quán)調(diào)度算法和需要時(shí)間片的轉(zhuǎn)法進(jìn)行了描述,并分析了它們的工作機(jī)理。
最高優(yōu)先權(quán)調(diào)度算法的基本思想是把CPU分配給就緒隊(duì)列中優(yōu)先權(quán)最高的進(jìn)程。靜態(tài)優(yōu)先數(shù)是在創(chuàng)建進(jìn)程時(shí)確定的,并在整個(gè)進(jìn)程運(yùn)行期間不再改變。
簡(jiǎn)單輪轉(zhuǎn)法的基本思想是:所有就緒進(jìn)程按 FCFS排成一個(gè)隊(duì)列,總是把處理機(jī)分配給隊(duì)首的進(jìn)程,各進(jìn)程占用CPU的時(shí)間片相同。如果運(yùn)行進(jìn)程用完它的時(shí)間片后還未完成,就把它送回到就緒隊(duì)列的末尾,把處理機(jī)重新分配給隊(duì)首的進(jìn)程,直至所有的進(jìn)程運(yùn)行完畢。
然后用具體語言模擬了一個(gè)進(jìn)程調(diào)度的程序。用戶可以自己輸入產(chǎn)生進(jìn)程,然后選擇調(diào)度方式進(jìn)行調(diào)度。所用的語言為VisualBasic.Net,結(jié)果顯示了調(diào)度運(yùn)行過程。
問題描述和分析 ……………………………………………… 4
算法設(shè)計(jì) …………………………………………………… 5
源代碼及說明 ………………………………………………… 5
結(jié)果與分析 ………………………………………………………17
參考文獻(xiàn)……………………………………………………… 18
一、問題描述和分析
問題描述
CPU調(diào)度是多道程序操作系統(tǒng)的基礎(chǔ),幾乎所有計(jì)算機(jī)資源在使用前都要被調(diào)度,因此,CPU調(diào)度對(duì)于操作系統(tǒng)來說非常重要。
假如操作系統(tǒng)中存在若干進(jìn)程,這些進(jìn)程,將會(huì)被按照指定的調(diào)度方式,由CPU進(jìn)行調(diào)度。
本程序,用來模擬實(shí)現(xiàn)操作系統(tǒng)中的兩種調(diào)度方法,即:優(yōu)先權(quán)調(diào)度和輪轉(zhuǎn)法調(diào)度。
下面對(duì)四種調(diào)度方法進(jìn)行描述
優(yōu)先權(quán)調(diào)度(priority-scheduling algorithm):在這種方式下,每一個(gè)進(jìn)程都有一個(gè)優(yōu)先權(quán)與其關(guān)聯(lián),具有最高優(yōu)先權(quán)的進(jìn)程會(huì)被分配到CPU,具有相同優(yōu)先權(quán)的進(jìn)程按FCFS順序調(diào)度。
輪轉(zhuǎn)法(round-robin):這種調(diào)度方式是專門為分時(shí)系統(tǒng)而設(shè)計(jì)的。它類似于FCFS調(diào)度,但是增加了搶占以在進(jìn)程是。定義一個(gè)較小時(shí)間單元,稱為時(shí)間量或時(shí)間片。時(shí)間片通常為10ms到100ms。為每個(gè)進(jìn)程分配不超過一個(gè)時(shí)間片間隔的CPU。
分析
根據(jù)描述確定解決方法。本程序利用VisualBasic.Net語言實(shí)現(xiàn)。首先定義一個(gè)進(jìn)程的類,包括進(jìn)程名、達(dá)到時(shí)間、服務(wù)時(shí)間、優(yōu)先權(quán)。再定義一個(gè)調(diào)度類,用以實(shí)現(xiàn)調(diào)度算法。
最后在主程序中,用戶可選擇兩種調(diào)度算法,確定問題的類型。
二、算法設(shè)計(jì)
主要設(shè)計(jì)思想
在主程序中,通過選擇結(jié)構(gòu),調(diào)用兩種調(diào)度算法。
各種調(diào)度算法實(shí)現(xiàn)
首先建立一個(gè)進(jìn)程類, 然后建立一個(gè)調(diào)度類,通過這個(gè)類來執(zhí)行調(diào)度算法。再建立一個(gè)鏈表,用來存放這些進(jìn)程。
優(yōu)先權(quán)調(diào)度:在優(yōu)先權(quán)調(diào)度中,每產(chǎn)生一個(gè)進(jìn)程,程序會(huì)記錄進(jìn)程的優(yōu)先權(quán),然后按產(chǎn)生的先后順序插入。當(dāng)當(dāng)前進(jìn)程結(jié)束時(shí),程序從鏈表中取出一個(gè)優(yōu)先權(quán)最高的進(jìn)程執(zhí)行。
輪轉(zhuǎn)法調(diào)度:由用戶定義一個(gè)時(shí)間片。在每個(gè)時(shí)間片中,程序執(zhí)行一個(gè)進(jìn)程。當(dāng)時(shí)間片結(jié)束后,程序?qū)⒔Y(jié)束當(dāng)前執(zhí)行的進(jìn)程,從鏈表中調(diào)入下一個(gè)進(jìn)程,并將當(dāng)前執(zhí)行的進(jìn)程插入到鏈表尾部。整個(gè)鏈表相當(dāng)于一個(gè)循環(huán)隊(duì)列。
三、源代碼及說明
1優(yōu)先級(jí)調(diào)度算法源代碼
Dim a As Integer
Dim b As Integer
Dim c As Integer
Dim d As Integer
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If Label7.Width < 200 Then
Label7.Visible = True
Label7.Width += 10
Label17.Visible = True
Label16.Visible = False
Label18.Visible = False
Else
Label17.Visible = False
Label18.Visible = False
Label16.Visible = True
a = 6
End If
If a < b And a < c And a < d Then
Timer1.Enabled = True
End If
If b < a And b < c And b < d Then
Timer2.Enabled = True
End If
If c < a And c < b And c < d Then
Timer3.Enabled = True
End If
If d < a And d < b And d < c Then
Timer4.Enabled = True
End If
End Sub
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
If Label8.Width < 200 Then
Label8.Visible = True
Label8.Width += 10
Label20.Visible = True
Label19.Visible = False
Label21.Visible = False
Else
Label20.Visible = False
Label21.Visible = False
Label19.Visible = True
b = 7
End If
If a < b And a < c And a < d Then
Timer1.Enabled = True
End If
If b < a And b < c And b < d Then
Timer2.Enabled = True
End If
If c < a And c < b And c < d Then
Timer3.Enabled = True
End If
If d < a And d < b And d < c Then
Timer4.Enabled = True
End If
End Sub
Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
If Label9.Width < 200 Then
Label9.Visible = True
Label9.Width += 10
Label23.Visible = True
Label22.Visible = False
Label24.Visible = False
Else
Label23.Visible = False
Label24.Visible = False
Label22.Visible = True
c = 8
End If
If a < b And a < c And a < d Then
Timer1.Enabled = True
End If
If b < a And b < c And b < d Then
Timer2.Enabled = True
End If
If c < a And c < b And c < d Then
Timer3.Enabled = True
End If
If d < a And d < b And d < c Then
Timer4.Enabled = True
End If
End Sub
Private Sub Timer4_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer4.Tick
If Label10.Width < 200 Then
Label10.Visible = True
Label10.Width += 10
Label26.Visible = True
Label25.Visible = False
Label27.Visible = False
Else
Label26.Visible = False
Label27.Visible = False
Label25.Visible = True
d = 9
End If
If a < b And a < c And a < d Then
Timer1.Enabled = True
End If
If b < a And b < c And b < d Then
Timer2.Enabled = True
End If
If c < a And c < b And c < d Then
Timer3.Enabled =True
End If
If d < a And d < b And d < c Then
Timer4.Enabled = True
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.Close()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
a = TextBox1.Text
b = TextBox2.Text
c = TextBox3.Text
d = TextBox4.Text
If a < b And a < c And a < d Then
Timer1.Enabled = True
End If
If b < a And b < c And b < d Then
Timer2.Enabled = True
End If
If c < a And c < b And c < d Then
Timer3.Enabled = True
End If
If d < a And d < b And d < c Then
Timer4.Enabled = True
End If
TextBox1.Enabled = False
TextBox2.Enabled = False
TextBox3.Enabled = False
TextBox4.Enabled = False
Button1.Enabled = False
Button2.Enabled = True
Label18.Visible = True
Label21.Visible = True
Label24.Visible = True
Label27.Visible = True
End Sub
End Class
2輪轉(zhuǎn)法調(diào)度源代碼
'
Dim a As Integer
Dim b As Integer
Dim c As Integer
Dim d As Integer
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.Close()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
a = TextBox1.Text
b = TextBox2.Text
c = TextBox3.Text
d = TextBox4.Text
If a > 0 And b > 0 And c > 0 And d > 0 Then
Timer1.Enabled() = True
End If
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim i As Integer
i = a - Label7.Width
If i < 20 Then
Label7.Width = Label7.Width + i
Label18.Visible = False
Label17.Visible = False
Label16.Visible = True
Timer1.Enabled = False
Timer2.Enabled = True
End If
If Label7.Width < a Then
Label7.Width = Label7.Width + 10
Label18.Visible = True
Label17.Visible = False
Label16.Visible = False
Timer1.Enabled = False
Timer2.Enabled = True
Else
Label18.Visible = False
Label17.Visible = False
Label16.Visible = True
Timer1.Enabled = False
Timer2.Enabled = True
End If
If Label8.Width >= b Then
Label21.Visible = False
Label20.Visible = False
Label19.Visible = True
Else
Label21.Visible = False
Label20.Visible = True
Label19.Visible = False
End If
If Label7.Width < a And Label8.Width >= b And Label9.Width >= c And Label10.Width >= d Then
Label18.Visible = False
Label17.Visible = True
Label16.Visible = False
ElseIf Label29.Width = a Then
Label18.Visible = False
Label17.Visible = False
Label16.Visible = True
End If
End Sub
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
Dim i As Integer
i = b - Label8.Width
If i < 20 Then
Label8.Width += i
Label21.Visible = False
Label20.Visible = False
Label19.Visible = True
Timer2.Enabled = False
Timer3.Enabled = True
End If
If Label8.Width < b Then
Label8.Width += 10
Label21.Visible = True
Label20.Visible = False
Label19.Visible = False
Timer2.Enabled = False
Timer3.Enabled = True
Else
Label21.Visible = False
Label20.Visible = False
Label19.Visible = True
Timer2.Enabled = False
Timer3.Enabled = True
End If
If Label9.Width >= c Then
Label24.Visible = False
Label23.Visible = False
Label22.Visible = True
Else
Label24.Visible = False
Label23.Visible = True
Label22.Visible = False
End If
If Label8.Width < b And Label7.Width >= a And Label9.Width >= c And Label10.Width >= d Then
Label21.Visible = False
Label20.Visible = True
Label19.Visible = False
ElseIf Label8.Width = b Then
Label21.Visible = False
Label20.Visible = False
Label19.Visible = True
End If
End Sub
Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
Dim i As Integer
i = c - Label9.Width
If i < 20 Then
Label9.Width += i
Label24.Visible = False
Label23.Visible = False
Label22.Visible = True
Timer3.Enabled = False
Timer4.Enabled = True
End If
If Label9.Width < c Then
Label9.Width += 10
Label24.Visible = True
Label23.Visible = False
Label22.Visible = False
Timer3.Enabled = False
Timer4.Enabled = True
Else
&nbnbsp; Label27.Visible = True
Label26.Visible = False
Label25.Visible = False
Timer4.Enabled = False
Timer1.Enabled = True
Else
Label27.Visible = False
Label26.Visible = False
Label25.Visible = True
Timer4.Enabled = False
Timer1.Enabled = True
End If
If Label7.Width >= a Then
Label18.Visible = False
Label17.Visible = False
Label16.Visible = True
Else
Label18.Visible = False
Label17.Visible = True
Label16.Visible = False
End If
If Label10.Width < d And Label7.Width >= a And Label8.Width >= b And Label9.Width >= c Then
Label27.Visible = False
Label26.Visible = True
Label25.Visible = False
ElseIf Label10.Width = d Then
Label27.Visible = False
Label26.Visible = False
Label25.Visible = True
End If
End Sub
Private Sub Form5_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
四、結(jié)果與討論
1優(yōu)先權(quán)調(diào)度算法結(jié)果圖
2 輪轉(zhuǎn)法的程序結(jié)果圖
5.結(jié)果分析:
經(jīng)選擇調(diào)度算法后,每種調(diào)度算法都能成功地執(zhí)行。所以,本次課程設(shè)計(jì)成功。 五、參考文獻(xiàn)
1、《Windows操作系統(tǒng)原理》 陳向群等著 機(jī)械工業(yè)出版社
2、《VisualBasic.Net程序設(shè)計(jì)》馮博琴 崔舒寧著 清華大學(xué)出版社
3、《操作系統(tǒng) 原理·技術(shù)與編程》 蔣靜, 徐志偉著 機(jī)械工業(yè)出版社
【操作系統(tǒng)課程設(shè)計(jì)報(bào)告模擬進(jìn)程調(diào)度程序(一)】相關(guān)文章:
課程設(shè)計(jì)報(bào)告07-20
C語言程序設(shè)計(jì) (一)05-11
從程序本位到程序自治06-04
施工組織設(shè)計(jì)課程設(shè)計(jì)開題報(bào)告07-13
經(jīng)濟(jì)全球化進(jìn)程中的新世紀(jì)世界格局05-30
開題會(huì)的程序03-07
本質(zhì)安全型集中式控制安全操作系統(tǒng)研究08-22
如何在 Windows操作系統(tǒng)中改變文件打開方式05-30
批捕聽證程序初探08-15