⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 操作系统源程序.txt

📁 操作系统源程序.rar
💻 TXT
字号:
操作系统源程序
信息013班,顾艳萍,23号
实验一:
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 "进程名不能为空", 48, "警告!"
ElseIf Text5.Text = Run1.NAME Then
 Waiting(N) = Run1
 wait(0).List(N) = Run1.NAME
 wait(1).List(N) = Run1.PRIORITY
 N = N + 1
 List3(0).List(0) = ""
 List3(1).List(0) = ""
 List3(2).List(0) = ""
 R1 = R1 - 1
 Run1.NAME = ""
 Run1.PRIORITY = 0
 Run1.RUNTIME = 0
ElseIf Text5.Text = Run2.NAME Then
 Waiting(N) = Run2
 wait(0).List(N) = Run2.NAME
 wait(1).List(N) = Run2.PRIORITY
 N = N + 1
 List3(0).List(0) = ""
 List3(1).List(0) = ""
 List3(2).List(0) = ""
 R1 = R1 - 1
 Run2.NAME = ""
 Run2.PRIORITY = 0
 Run2.RUNTIME = 0
Else
 MsgBox "输入进程名错误,请重新输入", 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).NAME Then
   flag = True
   k = j
  End If
 Next j
 If flag = False Then
  MsgBox "输入进程名错误,请重输", 48, "警告!"
 End If
 If flag = True Then    '找到解挂队列,添加到就绪队列'
  Rea(Re) = Waiting(k)
  Re = Re + 1
  For j = 0 To Re - 1  '将就绪队列按优先级排序'
   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).NAME
    ready(1).List(j) = Rea(j).PRIORITY
  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)
  Next j
  wait(0).List(N - 1) = ""
  wait(1).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
 Run1 = Rea(0)
 List3(0).List(0) = Run1.NAME
 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).NAME
  ready(1).List(j) = Rea(j).PRIORITY
 Next j
  ready(0).List(j) = ""
  ready(1).List(j) = ""
 Re = Re - 1
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) = ""
      R1 = 0
      Run1.NAME = ""
      Run1.PRIORITY = 0
      Run1.RUNTIME = 0
 End If
End If
If Re - 1 = 0 And R1 = 0 And R2 = 0 Then
RUN.Enabled = False
hangup.Enabled = False
Timer1.Enabled = False
Timer2.Enabled = False
Else
Timer2.Enabled = True
Timer1.Enabled = False
End If
End Sub

Private Sub Timer2_Timer()
Dim j As Integer, k As Integer
If R2 = 0 Then
 Run2 = Rea(0)
 List1(0).List(0) = Run2.NAME
 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).NAME
  ready(1).List(j) = Rea(j).PRIORITY
 Next j
  ready(0).List(j) = ""
  ready(1).List(j) = ""
 Re = Re - 1
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
      Run2.NAME = ""
      Run2.PRIORITY = 0
      Run2.RUNTIME = 0
 End If
End If
If Re - 1 = 0 And R1 = 0 And R2 = 0 Then
RUN.Enabled = False
hangup.Enabled = False
Timer1.Enabled = False
Timer2.Enabled = False
Else
Timer1.Enabled = True
Timer2.Enabled = False
End If
End Sub

实验二:
Private Type PCB
name As String
time As Integer
priority As Integer
zcdx As Integer
qswz As Integer
End Type
Private Type FPNC
start As Integer
need As Integer
End Type
Dim huishou(10) As FPNC
Dim i As Integer
Dim p(20) As PCB
Dim n As Integer
Dim s As Integer
Dim length As Integer
Dim qishi As Integer
Dim t As Integer
Private Sub add_Click()                    '添加进程,并放入进程数组中'
  If s Mod 2 = 0 Then
add.Caption = "清除"
If zhucun.Text > length Then
     MsgBox ("没有足够的内存分配")
     s = s + 1
     Exit Sub
  End If
p(n).name = jcm.Text
p(n).priority = pri.Text
p(n).time = shijian.Text
p(n).zcdx = zhucun.Text
Call allocate
i = i + 1
n = n + 1

Else
add.Caption = "添加"
jcm.Text = ""
pri.Text = ""
shijian.Text = ""
zhucun.Text = ""
End If
s = s + 1
End Sub

Private Sub Command1_Click()                 '开始, 结束按钮'
Timer1.Enabled = True
End Sub

Private Sub Command2_Click()                        '整理内存'
  if
End Sub

Private Sub Form_Load()
un_allocate.List(0) = " 起址  长度  状态 "          ' 假设内存分配情况,构造未分分区表'
un_allocate.List(1) = " 10    250   未分配 "
jincheng.List(0) = " 进程名 优先权 需要内存 内存始址"
i = 1
n = 0
t = 1
s = 0
length = 200
qishi = 20
Timer1.Enabled = False
End Sub

Private Sub Timer1_Timer()
Dim cha  As PCB
For a = 0 To b - 1                                  '按优先级由大到小排队'
   For b = 1 To i
    If p(a).priority < p(b).priority Then
       cha = p(a)
       p(a) = p(b)
       p(b) = cha
    End If
  Next
Next
'************循环未执行!!
    If p(0).time = 0 Then                          '如果进程运行完,调用rollback子程序回收内存分配'
       Call rollback
       For m = 0 To i - 1
        p(m) = p(m + 1)
       Next
       i = i - 1
       For k = 1 To i
       jincheng.List(k) = " " & p(k - 1).name & "     " & p(k - 1).priority & "     " & p(k - 1).zcdx & "    " & p(k - 1).qswz
       Next
   End If
  Text1.Text = p(0).name
  p(0).time = p(0).time - 1
 End Sub
Private Sub allocate()                                   '内存分配函数'
  
     p(n).qswz = qishi
   jincheng.List(i) = " " & p(n).name & "     " & p(n).priority & "     " & p(n).zcdx & "        " & p(n).qswz

  qishi = qishi + p(n).zcdx                                '改变未分分区表'
  length = length - p(n).zcdx
  un_allocate.List(1) = " " & qishi & "    " & length & "   未分配 "
  huishou(0).start = qishi                                 '记录未分分区表的起始位置和所剩大小'
  huishou(0).need = length
  
End Sub
Private Sub rollback()
  huishou(t).need = p(0).zcdx
  huishou(t).start = p(0).qswz
  un_allocate.List(t + 1) = " " & huishou(t).start & "       " & huishou(t).need & "  未分配"
  t = t + 1
End Sub



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -