running=[]
ready=[]
block=[]
#用列表存储进程
#菜单函数
def menu():
pass
print('{:*^30}'.format(''))
print('{: ^30}'.format('1.创建进程'))
print('{: ^30}'.format('2.时间片结束'))
print('{: ^30}'.format('3.阻塞进程'))
print('{: ^30}'.format('4.唤醒进程'))
print('{: ^30}'.format('5.结束进程'))
print('{: ^30}'.format('6.退出'))
print('{:*^30}'.format(''))
#创建进程
def creatNewProcess():
temp = input('请输入进程名称:')
if len(running)==0:
running.append(temp)
else:
ready.append(temp)
# print(ready)
#时间片到
def timeOut():
if len(running)!=0:
ready.append(running[0])
del running[0]
running.append(ready[0])
del ready[0]
#阻塞进程
def blockProces():
if len(running)!=0:
block.append(running[0])
del running[0]
if len(ready)!=0:
running.append(ready[0])
del ready[0]
#唤醒进程
def wakeProcess():
if len(block)!=0:
ready.append(block[0])
del block[0]
#结束进程
def endProcess():
if len(running)!=0:
del running[0]
if len(ready)!=0:
running.append(ready[0])
del ready[0]
#显示
def display():
print('running:', end=' ')
for i in range(len(running)):
print(running[i], end=' ')
print()
print('ready:',end=' ')
for i in range(len(ready)):
print(ready[i],end=' ')
print()
print('block:',end=' ')
for i in range(len(block)):
print(block[i],end=' ')
print()
#主函数
if __name__=='__main__':
while 1:
menu()
temp=input('请选择功能:')
if temp=='1':
creatNewProcess()
display()
elif temp=='2':
timeOut()
display()
elif temp=='3':
blockProces()
display()
elif temp=='4':
wakeProcess()
display()
elif temp=='5':
endProcess()
display()
elif temp=='6':
exit()
else:
print('输错了!')
计算机操作系统实验
最新推荐文章于 2024-09-09 10:11:43 发布