• 大小: 3KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-05-27
  • 语言: Python
  • 标签: python  操作系统  

资源简介

电子科技大学操作系统进程管理过程模拟 基于python编写,有问题csdn交流。

资源截图

代码片段和文件信息

#coding=utf-8

#以下是进程类
########################################################################################################################

#进程类的定义
class process():
    def __init__(selfpidpriority):
        self.pid = pid
        self.cpu_state = None
        self.memory = None
        self.open_file = None
        self.status = ‘ready‘
        self.childs = []
        self.priority = priority
        self.father = None
        self.reqRes = {}

    #进程创建进程,参数1为子进程id参数2位子进程优先级
    def create_process(selfchild_pidchild_priority):
        child_process = process(child_pidchild_priority)
        child_process.father = self
        tempProcess = None
        #下面的操作处理子进程列表
        if int(self.priority) >= int(child_priority):
            readyList_add(child_process)
            if self.childs == []:
                self.childs.append(child_process)
            else:
                for c in self.childs:
                    if int(c.priority) == int(child_priority):
                        pass
                    else:
                        tempProcess = c
                        break
                if tempProcess == None:
                    self.childs.append(child_process)
                else:
                    self.childs.insert(self.childs.index(tempProcess)child_process)
            scheduler()

        else:
            global  running_process
            running_process = child_process
            readyList_add(self)
            scheduler()

    #销毁进程,同时销毁由其创建的子进程。
    def destroy_process(selfpid):
        if running_process.pid == pid:
            for p in running_process.childs:
                self.destroy_process(p.pid)
            timeOut()
        else:
            for p in readyList:
                if p.pid == pid:
                    readyList.remove(p)
                    for i in p.childs:
                        self.destroy_process(i.pid)
            for p in blockList:
                if p.pid == pid:
                    blockList.remove(p)
                    for i in p.childs:
                        self.destroy_process(i.pid)
            timeOut()

    #进程申请资源,参数1为资源id,参数2位资源数量
    def requestSource(selfridcount):
        global rListrunning_process
        if rid not in ridList:
            print(“对不起,无此资源“)
            return
        else:
            for r in rList:
                if rid == r.rid:
                    if int(rList[rList.index(r)].maxCount )< int(count):
                        print(‘对不起,超出资源最大数量。‘)
                    elif int(rList[rList.index(r)].count )>=int( count):
                        rList[rList.index(r)].count -= int(count)
                        self.reqRes[rid] = count
                        scheduler()
                    elif int(rList[rList.index(r)].count )< int(count):
                        blockList_add(self)
                        self.status = ‘blocked‘
                        running_process = readyList[0]
                        readyList_remove(readyLis

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-03-20 06:41  processMaster-master\
     文件          35  2018-03-20 06:41  processMaster-master\README.md
     文件        9552  2018-03-20 06:41  processMaster-master\processManager.py
     文件          69  2018-03-20 06:41  processMaster-master\sortTest.py

评论

共有 条评论