操作系统课程设计报告模拟进程调度程序(一)

时间:2024-05-13 21:32:34 计算机毕业论文 我要投稿
  • 相关推荐

操作系统课程设计报告模拟进程调度程序(一)

此设计报告是对操作系统中进程调度的两种算法,即静态优先权调度算法和需要时间片的转法进行了描述,并分析了它们的工作机理。
 最高优先权调度算法的基本思想是把CPU分配给就绪队列中优先权最高的进程。静态优先数是在创建进程时确定的,并在整个进程运行期间不再改变。
 简单轮转法的基本思想是:所有就绪进程按 FCFS排成一个队列,总是把处理机分配给队首的进程,各进程占用CPU的时间片相同。如果运行进程用完它的时间片后还未完成,就把它送回到就绪队列的末尾,把处理机重新分配给队首的进程,直至所有的进程运行完毕。
 然后用具体语言模拟了一个进程调度的程序。用户可以自己输入产生进程,然后选择调度方式进行调度。所用的语言为VisualBasic.Net,结果显示了调度运行过程。

操作系统课程设计报告模拟进程调度程序(一)

问题描述和分析 ………………………………………………   4
算法设计   ……………………………………………………   5
源代码及说明 …………………………………………………   5
结果与分析 ………………………………………………………17
参考文献………………………………………………………   18

一、问题描述和分析
问题描述
 CPU调度是多道程序操作系统的基础,几乎所有计算机资源在使用前都要被调度,因此,CPU调度对于操作系统来说非常重要。
 假如操作系统中存在若干进程,这些进程,将会被按照指定的调度方式,由CPU进行调度。
 本程序,用来模拟实现操作系统中的两种调度方法,即:优先权调度和轮转法调度。
 下面对四种调度方法进行描述
 优先权调度(priority-scheduling algorithm):在这种方式下,每一个进程都有一个优先权与其关联,具有最高优先权的进程会被分配到CPU,具有相同优先权的进程按FCFS顺序调度。
 轮转法(round-robin):这种调度方式是专门为分时系统而设计的。它类似于FCFS调度,但是增加了抢占以在进程是。定义一个较小时间单元,称为时间量或时间片。时间片通常为10ms到100ms。为每个进程分配不超过一个时间片间隔的CPU。
分析
 根据描述确定解决方法。本程序利用VisualBasic.Net语言实现。首先定义一个进程的类,包括进程名、达到时间、服务时间、优先权。再定义一个调度类,用以实现调度算法。
 最后在主程序中,用户可选择两种调度算法,确定问题的类型。

二、算法设计
主要设计思想
 在主程序中,通过选择结构,调用两种调度算法。
 各种调度算法实现
 首先建立一个进程类, 然后建立一个调度类,通过这个类来执行调度算法。再建立一个链表,用来存放这些进程。
 优先权调度:在优先权调度中,每产生一个进程,程序会记录进程的优先权,然后按产生的先后顺序插入。当当前进程结束时,程序从链表中取出一个优先权最高的进程执行。
 轮转法调度:由用户定义一个时间片。在每个时间片中,程序执行一个进程。当时间片结束后,程序将结束当前执行的进程,从链表中调入下一个进程,并将当前执行的进程插入到链表尾部。整个链表相当于一个循环队列。
 
 
三、源代码及说明
1优先级调度算法源代码
    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轮转法调度源代码

            '
    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

四、结果与讨论
 1优先权调度算法结果图
 2 轮转法的程序结果图

5.结果分析:
     经选择调度算法后,每种调度算法都能成功地执行。所以,本次课程设计成功。            五、参考文献

1、《Windows操作系统原理》  陈向群等著 机械工业出版社
2、《VisualBasic.Net程序设计》冯博琴 崔舒宁著 清华大学出版社
3、《操作系统 原理·技术与编程》  蒋静, 徐志伟著 机械工业出版社

【操作系统课程设计报告模拟进程调度程序(一)】相关文章:

利用进程间通信实现程序自我保护分析03-09

基于μC/OS-II操作系统的任务调度机制03-04

基于Vxworks实时操作系统的串口通信程序设计与实现03-18

I2C总线在uClinux操作系统下的驱动程序设计11-22

组件机制与操作系统的实现03-18

人文导向牵动每一个国家全面拓展进程03-07

哈姆雷特:现代化进程的祭品03-08

分枝结构的程序设计 (一)03-07

C语言程序设计 (一)12-26