所以我必须为我的操作系统类实现一个离散事件 cpu 调度程序,但我不太明白它是如何工作的。我读过的每本解释/教科书总是用过于抽象的术语让我弄清楚它是如何工作的,也没有用 cpu bursts 和 io bursts 来表述(有些确实有用但仍然没有帮助够了)。
我不会发布任何我拥有的代码(实际上我写了很多,但我想在弄清楚(用特朗普的话说)实际发生了什么之后我会重写它)。相反,我只是想帮助找出一种我可以实现的伪代码。 我们有多个进程,具有到达时间 (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???
谢谢大家的帮助!
最佳答案
查看每个线程的到达时间,您可以对队列进行排序,使到达时间先出现的线程出现在到达时间较晚的线程之前。运行队列线程的前端(这是一个线程调度程序)。一次运行线程,当 burst 的 cpu 时间到了时,在队列后面输入一个新事件,其到达时间为当前时间加上 burst 的 io 时间(在到达时间再次对队列进行排序)。这样其他线程可以在一个线程执行 io 的同时执行。
(我的回答是假设你和我在同一个类(class)。[CIS*3110])
关于c - 进程调度器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35852756/