【发布时间】: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