?? 進(jìn)程調(diào)度xr.txt
字號(hào):
Option Explicit
Private Type PCB
PID As String '定義PCB
PRIORITY As Integer
RUNTIME As Integer
End Type
Private pro(20) As PCB, Run1 As PCB, Run2 As PCB, Rea(20) As PCB, Waiting(20) As PCB
Dim SUM As Integer, R1 As Integer, R2 As Integer, Re As Integer, N As Integer, x As Integer
Private Sub ADD_Click() '添加新進(jìn)程
Dim j As Integer, k As Integer
Dim S As PCB
If SUM > 20 Then
MsgBox "進(jìn)程已滿", 48, "警告!"
Exit Sub
Else
For j = 0 To SUM - 1
If pro(j).PID = Text1.Text Then
MsgBox "進(jìn)程名有重復(fù),請(qǐng)重新命名", 48, "警告!"
Exit Sub
End If
Next j
End If
If (Text1.Text = "" Or Text2.Text = "" Or Text3.Text = "") Then
MsgBox "要填的空不能為空", 48, "警告!"
Exit Sub
Else
With pro(SUM)
.PID = Text1.Text
.PRIORITY = CInt(Text3.Text)
.RUNTIME = CInt(Text2.Text)
End With
all.List(SUM) = pro(SUM).PID
SUM = SUM + 1
With Rea(Re)
.PID = Text1.Text
.PRIORITY = CInt(Text3.Text)
.RUNTIME = CInt(Text2.Text)
End With
Re = Re + 1
For j = 0 To Re - 1 '將就緒隊(duì)列按優(yōu)先級(jí)排序
For k = j + 1 To Re - 1
If Rea(j).PRIORITY < Rea(k).PRIORITY Then
S = Rea(j)
Rea(j) = Rea(k)
Rea(k) = S
End If
Next k
Next j
For j = 0 To Re - 1
ready(0).List(j) = Rea(j).PID
ready(1).List(j) = Rea(j).PRIORITY
ready(2).List(j) = Rea(j).RUNTIME
Next j
End If
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
RUN.Enabled = True
hangup.Enabled = True
release.Enabled = True
End Sub
Private Sub Form_Load()
SUM = 0
N = 0
Re = 0
R1 = 0
R2 = 0
x = -1
RUN.Enabled = False
hangup.Enabled = False
release.Enabled = False
Timer1.Enabled = False
Timer2.Enabled = False
End Sub
Private Sub hangup_Click()
Timer1.Enabled = False
Timer2.Enabled = False
If Text5.Text = "" Then
MsgBox "進(jìn)程名不能為空", 48, "警告!"
ElseIf Text5.Text = Run1.PID Then
Waiting(N) = Run1
wait(0).List(N) = Run1.PID
wait(1).List(N) = Run1.PRIORITY
wait(2).List(N) = Run1.RUNTIME
N = N + 1
List3(0).List(0) = ""
List3(1).List(0) = ""
List3(2).List(0) = ""
R1 = R1 - 1
ElseIf Text5.Text = Run2.PID Then
Waiting(N) = Run2
wait(0).List(N) = Run2.PID
wait(1).List(N) = Run2.PRIORITY
wait(2).List(N) = Run2.RUNTIME
N = N + 1
List3(0).List(0) = ""
List3(1).List(0) = ""
List3(2).List(0) = ""
R1 = R1 - 1
Else
MsgBox "輸入進(jìn)程名錯(cuò)誤,請(qǐng)重新輸入", 48, "警告!"
End If
Text5.Text = ""
Timer1.Enabled = True
End Sub
Private Sub release_Click()
Dim j As Integer, k As Integer
Dim flag As Boolean
Dim S As PCB
flag = False
Timer1.Enabled = False
Timer2.Enabled = False
If Text4.Text = "" Then
MsgBox "要填的空不能為空", 48, "警告!"
Else
For j = 0 To N - 1
If Text4.Text = Waiting(j).PID Then
flag = True
k = j
End If
Next j
If flag = False Then
MsgBox "輸入進(jìn)程名錯(cuò)誤,請(qǐng)重輸", 48, "警告!"
End If
If flag = True Then '找到解掛隊(duì)列,添加到就緒隊(duì)列
RUN.Enabled = True
hangup.Enabled = True
Rea(Re) = Waiting(k)
Re = Re + 1
For j = 0 To Re - 1 '將就緒隊(duì)列按優(yōu)先級(jí)排序
For k = j + 1 To Re - 1
If Rea(j).PRIORITY < Rea(k).PRIORITY Then
S = Rea(j)
Rea(j) = Rea(k)
Rea(k) = S
End If
Next k
Next j
For j = 0 To Re - 1
ready(0).List(j) = Rea(j).PID
ready(1).List(j) = Rea(j).PRIORITY
ready(2).List(j) = Rea(j).RUNTIME
Next j
For j = k To N - 2
Waiting(k) = Waiting(k + 1)
wait(0).List(k) = wait(0).List(k + 1)
wait(1).List(k) = wait(1).List(k + 1)
wait(2).List(k) = wait(2).List(k + 1)
Next j
wait(0).List(N - 1) = ""
wait(1).List(N - 1) = ""
wait(2).List(N - 1) = ""
N = N - 1
End If
End If
Text4.Text = ""
Timer1.Enabled = True
Timer2.Enabled = True
End Sub
Private Sub RUN_Click()
Timer1.Enabled = True
End Sub
Private Sub STOP_Click()
Timer1.Enabled = False
Timer2.Enabled = False
End Sub
Private Sub Timer1_Timer()
Dim j As Integer, k As Integer
If R1 = 0 Then
If Re > 0 Then
Run1 = Rea(0)
List3(0).List(0) = Run1.PID
List3(1).List(0) = Run1.RUNTIME
List3(2).List(0) = Run1.PRIORITY
R1 = 1
For j = 0 To Re - 1
Rea(j) = Rea(j + 1)
Next j
For j = 0 To Re - 2
ready(0).List(j) = Rea(j).PID
ready(1).List(j) = Rea(j).PRIORITY
ready(2).List(j) = Rea(j).RUNTIME
Next j
ready(0).List(j) = ""
ready(1).List(j) = ""
ready(2).List(j) = ""
Re = Re - 1
Else
Timer1.Enabled = False
Timer2.Enabled = False
RUN.Enabled = False
hangup.Enabled = False
List1(0).List(0) = ""
List1(1).List(0) = ""
List1(2).List(0) = ""
End If
Else
If Run1.RUNTIME > 0 Then
Run1.RUNTIME = Run1.RUNTIME - 1
List3(1).List(0) = Run1.RUNTIME
ElseIf Run1.RUNTIME = 0 Then
List3(0).List(0) = ""
List3(1).List(0) = ""
List3(2).List(0) = ""
End If
End If
Timer2.Enabled = True
Timer1.Enabled = False
End Sub
Private Sub Timer2_Timer()
Dim j As Integer, k As Integer
If R2 = 0 Then
If Re > 0 Then
Run2 = Rea(0)
List1(0).List(0) = Run2.PID
List1(1).List(0) = Run2.RUNTIME
List1(2).List(0) = Run2.PRIORITY
R2 = 1
For j = 0 To Re - 1
Rea(j) = Rea(j + 1)
Next j
For j = 0 To Re - 2
ready(0).List(j) = Rea(j).PID
ready(1).List(j) = Rea(j).PRIORITY
ready(2).List(j) = Rea(j).RUNTIME
Next j
ready(0).List(j) = ""
ready(1).List(j) = ""
ready(2).List(j) = ""
Re = Re - 1
Else
Timer1.Enabled = False
Timer2.Enabled = False
RUN.Enabled = False
hangup.Enabled = False
List1(0).List(0) = ""
List1(1).List(0) = ""
List1(2).List(0) = ""
End If
Else
If Run2.RUNTIME > 0 Then
Run2.RUNTIME = Run2.RUNTIME - 1
List1(1).List(0) = Run2.RUNTIME
ElseIf Run2.RUNTIME = 0 Then
List1(0).List(0) = ""
List1(1).List(0) = ""
List1(2).List(0) = ""
R2 = 0
End If
End If
Timer1.Enabled = True
Timer2.Enabled = False
End Sub
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -