【问题标题】:Process scheduler进程调度器
【发布时间】:2016-06-21 12:51:03
【问题描述】:

所以我必须为我的操作系统类实现一个离散事件 cpu 调度程序,但我不太明白它是如何工作的。我读过的每一个解释/教科书总是把事情用太抽象的术语来说明它实际上是如何工作的,也没有把事情放在 cpu 爆发和 io 爆发方面(有些做了但仍然没有帮助够了)。

我没有发布我拥有的任何代码(我实际上写了很多,但我想在我弄清楚(用特朗普的话来说)实际发生了什么之后我会重写它)。相反,我只想帮助找出一种我可以实现的伪代码。 我们有多个进程,它们具有到达时间 (AT)、总 Cpu (TC)、Cpu 突发 (CB) 和 Io 突发 (IO)。

假设给定我:p1 (AT=1, TC=200, CB=10, IO=20) 和 p2 (AT=1000, TC=200, CB=20, IO=10)。假设我正在实施先到先服务调度程序。

我还在不确定的地方加上问号 (?)。

Put all processes into eventQ
initialize all processes.state = CREATED
While(eventQueue not empty) process = eventQueue.getFront()

 if process.state==CREATED state, it can transition to ready
   clock= process.AT 
   process.state = READY
   then I add it back to the end (?) of the eventQueue.

 if process.state==READY, it can transition to run 
   clock= process.AT + process.CPU_time_had + process.IO_time_had (?)  
   CPU_Burst = process.CB * Rand(b/w 0 and process.CB)
   if (CB >= process.TC - process.CPU_time_had) 
       then it's done I don't add it back
       process.finish_time = clock + CB
       continue
   else 
       process.CPU_time_had += CB
       (?) Not sure if I put the process into BLOCK or READY here
       Add it to the back of eventQueue (?)

 if process.state==BLOCK
    No idea what happens (?) 
    Or do things never get Blocked in FCFS (which would make sense)
    Also how do IO bursts enter into this picture???

感谢大家的帮助!

【问题讨论】:

    标签: c process operating-system scheduler


    【解决方案1】:

    查看每个线程的到达时间,您可以对队列进行排序,使到达时间首先出现在到达时间较晚的线程之前。运行队列的最前面的线程(这是一个线程调度程序)。一次运行线程一个突发,当突发的cpu时间到时,在队列后面输入一个新事件,到达时间为当前时间加上突发的io时间(按到达时间再次排序队列)。这样其他线程可以在线程执行 io 时执行。

    (我的回答是假设你和我在同一个班。[CIS*3110])

    【讨论】:

    • 我很高兴有人理解它:) 我不知道线程“到达时间”可能是什么,或者“IO 突发”是什么:(
    • IO突发是如何进入这张图的?所以你说的是如果p1的到达时间+ cpu_burst
    • 它们不是 IO 突发。这是 CPU 爆发。每个 CPU 突发都会结束,无论是通过输出 IO 还是线程终止。在输入文件中,有到达时间,即每个线程到达的时间。因此,第一个 CPU 突发到达线程的到达时间。每个后续突发的到达时间是该线程的上一个突发结束的时间,加上上一个突发的 IO 时间。这个想法是线程在 CPU 中执行一些事情,离开 IO,然后在完成获取 IO 后返回。因此,调度线程,并在线程中断时随机排列队列
    猜你喜欢
    • 2012-04-23
    • 2013-09-03
    • 2013-05-12
    • 2011-05-14
    • 1970-01-01
    • 1970-01-01
    • 2011-09-17
    • 2022-01-24
    • 2014-10-03
    相关资源
    最近更新 更多