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

📄 process.frm

📁 内存管理 内存管理 内存管理
💻 FRM
📖 第 1 页 / 共 4 页
字号:
         Begin VB.Menu state 
            Caption         =   "就绪"
            Index           =   2
         End
         Begin VB.Menu state 
            Caption         =   "等待"
            Index           =   3
         End
      End
      Begin VB.Menu fg2 
         Caption         =   "-"
      End
      Begin VB.Menu queuep 
         Caption         =   "设置优先级"
         Begin VB.Menu realtime 
            Caption         =   "实时"
         End
         Begin VB.Menu fg3 
            Caption         =   "-"
         End
         Begin VB.Menu queue 
            Caption         =   "高"
            Index           =   1
         End
         Begin VB.Menu queue 
            Caption         =   "高于标准"
            Index           =   2
         End
         Begin VB.Menu queue 
            Caption         =   "标准"
            Index           =   3
         End
         Begin VB.Menu queue 
            Caption         =   "低于标准"
            Index           =   4
         End
         Begin VB.Menu queue 
            Caption         =   "低"
            Index           =   5
         End
      End
   End
   Begin VB.Menu help 
      Caption         =   "帮助(&H)"
      Begin VB.Menu help2 
         Caption         =   "帮助主题"
      End
      Begin VB.Menu help1 
         Caption         =   "关于作者"
      End
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim process(19, 8) As Integer
'0进程PCB(100--999);1进程大小(100--1024KB);2已执行大小;3状态位(1执行态,2就绪态,3等待态)
'4优先级位(1高优先级,2高于标准,3标准,4低于标准,5低优先级);5实时状态位(0关,1开).
'6进程分块数,7绿色值,8,蓝色值
Dim myram(16, 2) As Integer '0所存进程PCB,1所存进程页帧,2所对就应的内存页面
Dim r1 As Integer, r2 As Integer '实时进程控制时间
Dim t1 As Integer, t2 As Integer '分时进程控制时间
Dim flag1 As Integer '时间片控制
Dim pcb1 As Integer 'PCB
Dim p1 As Integer '当前执行进程
Dim flag2 As Boolean  '实时标志位
Dim amt As Integer '当前进程数
Dim flag3 As Boolean '是否打开快速新建进程通道
Dim flagc2 As Boolean '进程管理按钮是否按下
Dim flagc3 As Boolean '内存管理按钮是否按下
Dim page1 As Integer '当前进程执行页帧
Dim page2 As Integer '当前进程所在页面
Dim x1 As Integer
Dim rgb1 As Integer


Private Sub addp_Click()
    Dim r1 As Integer, x1 As Integer
    Timer1.Enabled = False
    Randomize
    If amt >= 20 Then
        r1 = MsgBox("对不起,打开进程数已满", vbCritical, "新建任务")
        Timer1.Enabled = True
        Exit Sub
    End If
    amt = amt + 1
    x1 = amt - 1
    process(x1, 0) = pcb1
    process(x1, 1) = Int(Rnd * 1024) + 100
    process(x1, 3) = 2
    process(x1, 4) = Int(Rnd * 5) + 1
    process(x1, 6) = Int(process(x1, 1) / 100) + 1
    rgb1 = pcb1
    While rgb1 > 255
    rgb1 = rgb1 - 200
    Wend
    process(x1, 7) = Int(Rnd * rgb1)
    process(x1, 8) = Int(Rnd * rgb1)
    If flag3 Then
        r1 = MsgBox("进程大小为" + CStr(process(x1, 1)) + "KB" + ",优先级为" + queue(process(x1, 4)).Caption, , "创建新任务")
    End If
    Label2.Caption = "进程数:" + CStr(amt)
    List1.AddItem "模拟进程" + CStr(process(x1, 0)) + Space(7) + CStr(state(process(x1, 3)).Caption) + Space(10) + "0%"
    Label8(x1).Visible = True
    Label8(x1).Caption = "进程" & CStr(pcb1)
    Label8(x1).BackColor = RGB(rgb1, process(x1, 7), process(x1, 8))
    pcb1 = pcb1 + 1
    Timer1.Enabled = True
End Sub

Private Sub closep_Click()
    Command1_Click
End Sub

Private Sub Command1_Click()
    Dim i As Integer
    Dim j As Integer
    If List1.ListIndex <> -1 Then
        Timer1.Enabled = False
        '释放进程所占内存
        For i = 0 To 16
            If myram(i, 0) = process(p1, 0) Then
                myram(i, 0) = 0
                myram(i, 1) = 0
                Label5(myram(i, 2)).BackColor = RGB(256, 256, 256)
            End If
        Next
        If List1.ListIndex < p1 Then
            p1 = p1 - 1
        End If
        If List1.ListIndex = p1 Then
            flag1 = 30
        End If
        amt = amt - 1
        For i = List1.ListIndex To amt - 1
            For j = 0 To 8
                process(i, j) = process(i + 1, j)
            Next
            rgb1 = process(i, 0)
            While rgb1 > 255
                rgb1 = rgb1 - 200
            Wend
            Label8(i).Caption = "进程" & CStr(process(i, 0))
            Label8(i).BackColor = RGB(rgb1, process(i, 7), process(i, 8))
        Next
        For j = 0 To 8
            process(i, j) = 0
        Next
        Label8(i).Visible = False
        Label2.Caption = "进程数:" + CStr(amt)
        List1.RemoveItem List1.ListIndex
        If amt <> 0 Then
            Timer1.Enabled = True
        End If
    End If
    command1.Enabled = False
    closep.Enabled = False
End Sub

Private Sub command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    commands(1).BackColor = RGB(225, 224, 210)
End Sub

Private Sub command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    commands(1).BackColor = RGB(252, 210, 122)
End Sub

Private Sub Command2_Click()
    flag3 = False
    addp_Click
    flag3 = True
End Sub

Private Sub command2_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    commands(0).BackColor = RGB(225, 224, 210)
End Sub

Private Sub command2_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    commands(0).BackColor = RGB(252, 210, 122)
End Sub


Private Sub endp_Click()
    Command1_Click
End Sub

Private Sub exit_Click()
    Unload Me
End Sub

Private Sub Form_Load()
    Dim i As Integer
    Form1.Width = 4650
    r1 = 1
    r2 = 0
    t1 = 1
    t2 = 0
    flag1 = 0
    flag2 = False
    flag3 = True
    pcb1 = 100
    amt = 0
    Timer1.Enabled = False
    command1.Enabled = False
    closep.Enabled = False
    flagc2 = True
    flagc3 = False
    Frame2.Top = 360
    Frame2.Left = 0
    Frame2.Visible = False
    page1 = 0
    page2 = 0
    For i = 0 To 16
        myram(i, 0) = 0
        myram(i, 1) = 0
        myram(i, 2) = i '对就内存页面编号
    Next
    For i = 0 To 19
        'Label8(i).ForeColor = RGB(252, 210, 122)
        Label8(i).Visible = False
    Next
    commands(2).BackColor = RGB(252, 210, 122)
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If flagc3 = False Then commands(3).BackColor = RGB(255, 255, 255)
    If flagc2 = False Then commands(2).BackColor = RGB(255, 255, 255)
End Sub

Private Sub Frame1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    commands(0).BackColor = RGB(255, 255, 255)
    commands(1).BackColor = RGB(255, 255, 255)
    commands(3).BackColor = RGB(255, 255, 255)
End Sub
Private Sub Frame2_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    commands(2).BackColor = RGB(255, 255, 255)
End Sub

Private Sub help1_Click()
    Dim r1 As Integer
    r1 = MsgBox("作者;王勇" + Chr$(13) + Chr$(10) + "Email:wy.sh@tom.com" + Space(10) + Chr$(13) + Chr$(10) + "QQ:13272572", 64, "帮助")
End Sub

Private Sub help2_Click()
    Dim r1 As Integer
    Dim msg1 As String
    msg1 = "Windows进程调度与内存存取模拟" + Chr$(13) + Chr$(10)
    msg1 = msg1 + "    ☆进程调度采用基于优先级的分时与实时调度策略(快捷菜单中)。" + Chr$(13) + Chr$(10)
    msg1 = msg1 + "     可以动态添加结束进程且可设置优先级和分时实时执行方式。" + Chr$(13) + Chr$(10)
    msg1 = msg1 + "    ☆内存存取采用基于页式管理方式的最久未使用页面替换策略。" + Chr$(13) + Chr$(10)
    msg1 = msg1 + "    ☆此程序仅是模拟程序,不对系统造成任何影响。" + Chr$(13) + Chr$(10)
    msg1 = msg1 + "    ☆此程序未经作者同意严禁传播。谢谢使用!" + Chr$(13) + Chr$(10)
    msg1 = msg1 + Space(40) + "2004年12月"
    r1 = MsgBox(msg1, 64, "帮助")
End Sub


Private Sub Label3_Click()
    flagc2 = True
    flagc3 = False
    Label3.BackColor = RGB(236, 233, 216)
    Label4.BackColor = RGB(255, 255, 255)
    commands(3).BackColor = RGB(255, 255, 255)
    Frame2.Visible = False
    Frame1.Visible = True
End Sub

Private Sub Label3_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    commands(2).BackColor = RGB(252, 210, 122)
End Sub

Private Sub Label4_Click()
    flagc3 = True
    flagc2 = False
    Label4.BackColor = RGB(236, 233, 216)
    Label3.BackColor = RGB(255, 255, 255)
    commands(2).BackColor = RGB(255, 255, 255)
    Frame1.Visible = False
    Frame2.Visible = True
End Sub

Private Sub Label4_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    commands(3).BackColor = RGB(252, 210, 122)
End Sub

Private Sub List1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Dim i As Integer
    If List1.ListIndex <> -1 Then
        command1.Enabled = True
    closep.Enabled = True
    End If
    If Button = 2 And List1.ListIndex <> -1 Then
        For i = 1 To 3
            state(i).Checked = False
        Next
        state(process(List1.ListIndex, 3)).Checked = True
        For i = 1 To 5
            queue(i).Checked = False
        Next
        queue(process(List1.ListIndex, 4)).Checked = True
        realtime.Checked = False
        If process(List1.ListIndex, 5) = 1 Then
            realtime.Checked = True
        End If
        PopupMenu kj1
    End If
End Sub

Private Sub queue_Click(Index As Integer)
    If process(p1, 4) < Index And process(List1.ListIndex, 4) < process(p1, 4) And process(p1, 5) = 0 Then
        Timer1.Enabled = False
        p1 = List1.ListIndex
        flag1 = 0
        Timer1.Enabled = True
    End If
    process(List1.ListIndex, 4) = Index
End Sub

Private Sub realtime_Click()
    On Error Resume Next
    process(List1.ListIndex, 5) = Abs(process(List1.ListIndex, 5) - 1)
End Sub

Private Sub Timer1_Timer()
    Dim i As Integer
    Dim j As Integer
    On Error Resume Next
    flag1 = flag1 + 1
    If flag1 >= 10 Then
        flag1 = 0
        process(p1, 3) = 2
        List1.List(p1) = "模拟进程" + CStr(process(p1, 0)) + Space(7) + CStr(state(process(p1, 3)).Caption) + Space(10) + CStr(Int(process(p1, 2) / process(p1, 1) * 100)) + "%"
'实时控制
        For r1 = 1 To 5
            For r2 = 0 To amt - 1
                If process(r2, 4) = r1 And process(r2, 5) = 1 Then
                    p1 = r2
                    flag2 = True
                    Label7(0).Caption = CStr(process(p1, 0))
                    GoTo l1
                End If
            Next
            r2 = 0
        Next
        r1 = 1
'分时控制
        While t1 <= 5
            While t2 <= amt - 1
                If process(t2, 4) = t1 Then
                    p1 = t2
                    flag2 = False
                    t2 = t2 + 1
                    Label7(0).Caption = CStr(process(p1, 0))
                    GoTo l1
                End If
                t2 = t2 + 1
            Wend
            t2 = 0
            t1 = t1 + 1
        Wend
        t1 = 1
    End If
'实时分时处理,
l1: If process(p1, 2) >= process(p1, 1) Then
        List1.Selected(p1) = True
        flag1 = 30
        flag2 = False
        Command1_Click
        Exit Sub
    End If
    '内存管理模式
    Randomize
    page1 = Int(Rnd * process(p1, 6)) + 1
    '从内存中搜索该页是否已在存在
    For i = 0 To 16
        If process(p1, 0) = myram(i, 0) And page1 = myram(i, 1) Then Exit For
    Next
    If i >= 17 Then '如果没有则搜索内存是否有空白页面
        For i = 0 To 16
            If myram(i, 0) = 0 Then Exit For
        Next
        i = 0 '如果没有则设被换页为第一页
    End If
    page2 = myram(i, 2) '保存被换页所对应的内存页号
    x1 = i + 1
    Do While i <= 15
        myram(i, 0) = myram(x1, 0)
        myram(i, 1) = myram(x1, 1)
        myram(i, 2) = myram(x1, 2)
        i = i + 1
        x1 = x1 + 1
    Loop
    myram(i, 0) = process(p1, 0)
    myram(i, 1) = page1
    myram(i, 2) = page2
    '内存管理图相控制
    rgb1 = process(p1, 0)
    While rgb1 > 255
        rgb1 = rgb1 - 200
    Wend
    Label5(myram(i, 2)).BackColor = RGB(rgb1, process(p1, 7), process(p1, 8))
    Line6(0).x1 = Label5(myram(i, 2)).Left
    Line6(0).X2 = Line6(0).x1 + 240
    Line6(1).X2 = Line6(0).x1
    Line6(1).x1 = Line6(0).x1 + 120
    Line6(2).X2 = Line6(0).x1 + 120
    Line6(2).x1 = Line6(0).X2
    Label7(1).Caption = CStr(myram(i, 1))
    '进程处理
    process(p1, 2) = process(p1, 2) + 10
    If process(p1, 2) > process(p1, 1) Then
        process(p1, 2) = process(p1, 1)
    End If
    process(p1, 3) = 1
    List1.List(p1) = "模拟进程" + CStr(process(p1, 0)) + Space(7) + CStr(state(process(p1, 3)).Caption) + Space(10) + CStr(Int(process(p1, 2) / process(p1, 1) * 100)) + "%"
    If flag2 = True Then
        flag1 = 0
    End If
End Sub

⌨️ 快捷键说明

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