예제 #1
0
def showRR():
    pcb1 = PCB(1, 11, [5, 5, 5], 10)
    pcb2 = PCB(2, 11, [5, 5, 5], 10)
    pcb3 = PCB(3, 11, [5, 5, 5], 10)
    pcb4 = PCB(4, 11, [5, 5, 5], 10)
    pcb5 = PCB(5, 11, [5, 5, 5], 10)
    PCBList = [pcb1, pcb2, pcb3, pcb4, pcb5]
    iter = processManage('RR', PCBList, 1)
    result = []
    while True:
        try:
            for dict in next(iter):
                result.append(dict)
            yield result
        except:
            break
예제 #2
0
def processCheck(
    PID,
    CpuTime,
    AllResource,
    re_mSize=10,
    intoTime=0,
    name='null',
    priority=0,
):
    # 检查PID是否已经存在
    if PID >= 0:
        try:
            # 检查进程ID是否存在
            processCheckList.index(PID)
            # 已经存在时返回空值
            return None
        except:
            # 不存在,记录该PID,并返回PCB对象
            processCheckList.append(PID)
            return PCB(PID,
                       CpuTime,
                       AllResource,
                       re_mSize,
                       intoTime=0,
                       name='null',
                       priority=0)
    else:
        print('PID格式输入错误')
        return None
예제 #3
0
def showSem():
    # 设置信号量
    semaphore = {'mex1': 1, 'mex2': 0, 'mex3': 0}
    # 信号量同步事件
    pcb1 = PCB(1, 5, [5, 5, 5], 10)
    pcb2 = PCB(2, 5, [5, 5, 5], 10)
    pcb3 = PCB(3, 5, [5, 5, 5], 10)

    pcb1.Semaphore = semaphore
    pcb2.Semaphore = semaphore
    pcb3.Semaphore = semaphore
    eventSem1 = {}
    eventSem1['CpuTime'] = 5
    eventSem1['task_application'] = 'S'
    eventSem1['re_mutex'] = ['mex1']  #获取 1
    eventSem1['Srequest'] = True

    eventSemR1 = {}
    eventSemR1['CpuTime'] = 2
    eventSemR1['task_application'] = 'S'
    eventSemR1['re_mutex'] = ['mex2', 'mex3']  #释放 2 3
    eventSemR1['Srequest'] = False

    eventSem2 = {}
    eventSem2['CpuTime'] = 4
    eventSem2['task_application'] = 'S'
    eventSem2['re_mutex'] = ['mex2']  # 获取 2
    eventSem2['Srequest'] = True

    eventSem3 = {}
    eventSem3['CpuTime'] = 10
    eventSem3['task_application'] = 'S'
    eventSem3['re_mutex'] = ['mex3']  # 获取 3
    eventSem3['Srequest'] = True

    pcb1.event.append(eventSem1)
    pcb1.event.append(eventSemR1)
    pcb2.event.append(eventSem2)
    pcb3.event.append(eventSem3)

    PCBList = [pcb1, pcb2, pcb3]
    iter = processManage('FIFS', PCBList)
    result = []
    try:
        for dict in next(iter):
            result.append(dict)
        yield result
    except:
        yield result  # 暂时先这样
예제 #4
0
def showReAndFile():
    # 资源事件
    eventResourceR1 = {}
    eventResourceR1['CpuTime'] = 30
    eventResourceR1['task_application'] = 'R'
    eventResourceR1['ResourceTime'] = 1
    eventResourceR1['re_Resource'] = [3, 3, 3]
    eventResourceR1['Rrequest'] = True

    eventResourceR2 = {}
    eventResourceR2['CpuTime'] = 29
    eventResourceR2['task_application'] = 'R'
    eventResourceR2['ResourceTime'] = 1
    eventResourceR2['re_Resource'] = [2, 2, 2]
    eventResourceR2['Rrequest'] = True

    eventResourceR3 = {}
    eventResourceR3['CpuTime'] = 28
    eventResourceR3['task_application'] = 'R'
    eventResourceR3['ResourceTime'] = 1
    eventResourceR3['re_Resource'] = [1, 2, 3]
    eventResourceR3['Rrequest'] = True

    eventResourceR4 = {}
    eventResourceR4['CpuTime'] = 27
    eventResourceR4['task_application'] = 'R'
    eventResourceR4['ResourceTime'] = 1
    eventResourceR4['re_Resource'] = [4, 3, 2]
    eventResourceR4['Rrequest'] = True

    # 添加文件事件
    eventFileF1 = {}
    eventFileF1['CpuTime'] = 30
    eventFileF1['task_application'] = 'F'
    eventFileF1['Frequest'] = 'storage'
    eventFileF1['FileName'] = 'C\\First\\newText\\newText1.txt'
    eventFileF1['re_fSize'] = 10
    eventFileF1['Ftype'] = 0

    eventFileF2 = {}
    eventFileF2['CpuTime'] = 30
    eventFileF2['task_application'] = 'F'
    eventFileF2['Frequest'] = 'storage'
    eventFileF2['FileName'] = 'C\\First\\newText\\newText2.txt'
    eventFileF2['re_fSize'] = 10
    eventFileF2['Ftype'] = 0

    eventFileF3 = {}
    eventFileF3['CpuTime'] = 28
    eventFileF3['task_application'] = 'F'
    eventFileF3['Frequest'] = 'storage'
    eventFileF3['FileName'] = 'C\\First\\newText\\newText3.txt'
    eventFileF3['re_fSize'] = 10
    eventFileF3['Ftype'] = 1

    eventFileF4 = {}
    eventFileF4['CpuTime'] = 28
    eventFileF4['task_application'] = 'F'
    eventFileF4['Frequest'] = 'storage'
    eventFileF4['FileName'] = 'C\\First\\newText\\newText4.txt'
    eventFileF4['re_fSize'] = 10
    eventFileF4['Ftype'] = 0

    eventFileF5 = {}
    eventFileF5['CpuTime'] = 26
    eventFileF5['task_application'] = 'F'
    eventFileF5['Frequest'] = 'storage'
    eventFileF5['FileName'] = 'C\\First\\oldText\\newText1.txt'
    eventFileF5['re_fSize'] = 10
    eventFileF5['Ftype'] = 0

    eventFileF6 = {}
    eventFileF6['CpuTime'] = 26
    eventFileF6['task_application'] = 'F'
    eventFileF6['Frequest'] = 'storage'
    eventFileF6['FileName'] = 'C\\First\\oldText\\newText2.txt'
    eventFileF6['re_fSize'] = 10
    eventFileF6['Ftype'] = 0

    eventFileF7 = {}
    eventFileF7['CpuTime'] = 25
    eventFileF7['task_application'] = 'F'
    eventFileF7['Frequest'] = 'delete'
    eventFileF7['FileName'] = 'C\\First\\newText\\newText4.txt'
    eventFileF7['re_fSize'] = 10
    eventFileF7['Ftype'] = 1

    eventFileF8 = {}
    eventFileF8['CpuTime'] = 25
    eventFileF8['task_application'] = 'F'
    eventFileF8['Frequest'] = 'delete'
    eventFileF8['FileName'] = 'C\\First\\newText\\newTex3.txt'
    eventFileF8['re_fSize'] = 10
    eventFileF8['Ftype'] = 1

    pcb1 = PCB(1, 35, [5, 5, 5], 10)
    pcb2 = PCB(2, 34, [5, 5, 5], 10)
    pcb3 = PCB(3, 33, [5, 5, 5], 10)
    pcb4 = PCB(4, 32, [5, 5, 5], 10)
    pcb5 = PCB(5, 31, [5, 5, 5], 10)

    # 资源事件添加
    pcb1.event.append(eventResourceR1)
    pcb1.event.append(eventResourceR2)
    pcb2.event.append(eventResourceR3)
    pcb2.event.append(eventResourceR4)
    # 文件事件添加
    pcb3.event.append(eventFileF1)
    pcb3.event.append(eventFileF2)
    pcb3.event.append(eventFileF3)
    pcb3.event.append(eventFileF4)
    pcb4.event.append(eventFileF5)
    pcb4.event.append(eventFileF6)
    pcb5.event.append(eventFileF7)
    pcb5.event.append(eventFileF8)
    PCBList = [pcb1, pcb2, pcb3, pcb4, pcb5]
    iter = processManage('RR', PCBList, 1)
    result = []
    try:
        for dict in next(iter):
            result.append(dict)
        yield result
    except:
        yield result  # 暂时先这样
예제 #5
0
def showDevice():
    #  创建设备事件
    eventDeviceA1 = {}
    eventDeviceA1['CpuTime'] = 30
    eventDeviceA1['task_application'] = 'D'
    eventDeviceA1['re_Dname'] = '设备A1'
    eventDeviceA1['DeviceTime'] = 5
    eventDeviceA1['Drequest'] = True

    eventDeviceB1 = {}
    eventDeviceB1['CpuTime'] = 30
    eventDeviceB1['task_application'] = 'D'
    eventDeviceB1['re_Dname'] = '设备B1'
    eventDeviceB1['DeviceTime'] = 5
    eventDeviceB1['Drequest'] = True

    eventDeviceB2 = {}
    eventDeviceB2['CpuTime'] = 30
    eventDeviceB2['task_application'] = 'D'
    eventDeviceB2['re_Dname'] = '设备B2'
    eventDeviceB2['DeviceTime'] = 5
    eventDeviceB2['Drequest'] = True

    eventDeviceC1 = {}
    eventDeviceC1['CpuTime'] = 30
    eventDeviceC1['task_application'] = 'D'
    eventDeviceC1['re_Dname'] = '设备C1'
    eventDeviceC1['DeviceTime'] = 5
    eventDeviceC1['Drequest'] = True

    eventDeviceC2 = {}
    eventDeviceC2['CpuTime'] = 30
    eventDeviceC2['task_application'] = 'D'
    eventDeviceC2['re_Dname'] = '设备C2'
    eventDeviceC2['DeviceTime'] = 5
    eventDeviceC2['Drequest'] = True

    eventDeviceC3 = {}
    eventDeviceC3['CpuTime'] = 30
    eventDeviceC3['task_application'] = 'D'
    eventDeviceC3['re_Dname'] = '设备C3'
    eventDeviceC3['DeviceTime'] = 5
    eventDeviceC3['Drequest'] = True

    # 设备事件添加测试
    pcb1 = PCB(1, 35, [5, 5, 5], 10)
    pcb2 = PCB(2, 34, [5, 5, 5], 10)
    pcb3 = PCB(3, 33, [5, 5, 5], 10)
    pcb4 = PCB(4, 32, [5, 5, 5], 10)
    pcb5 = PCB(5, 31, [5, 5, 5], 10)
    #   添加同设备事件
    pcb1.event.append(eventDeviceA1)
    pcb2.event.append(eventDeviceA1)
    # #   一个进程中添加多个设备申请事件
    pcb3.event.append(eventDeviceB1)
    pcb3.event.append(eventDeviceB2)
    # #   在一个进程中申请多种设备
    pcb4.event.append(eventDeviceB1)
    pcb4.event.append(eventDeviceC1)
    #     在一个进程中添加三种设备
    pcb5.event.append(eventDeviceA1)
    pcb5.event.append(eventDeviceB1)
    pcb5.event.append(eventDeviceC1)

    # 事件处理
    PCBList = [pcb1, pcb2, pcb3, pcb4, pcb5]
    iter = processManage('RR', PCBList, 1)
    result = []
    try:
        for dict in next(iter):
            result.append(dict)
        yield result
    except:
        yield result  # 暂时先这样
예제 #6
0
def showUnite():
    pcb1 = PCB(1, 10, [5, 5, 5], 10)
    pcb2 = PCB(2, 10, [5, 5, 5], 10)
    pcb3 = PCB(3, 10, [5, 5, 5], 10)
    pcb4 = PCB(4, 10, [5, 5, 5], 10)
    pcb5 = PCB(5, 10, [5, 5, 5], 10)

    # 进程名设置
    pcb1.name = '进程1'
    pcb2.name = '进程2'
    pcb3.name = '进程3'
    pcb4.name = '进程4'
    pcb5.name = '进程5'

    # 设置申请内存大小
    pcb1.re_mSize = 30
    pcb2.re_mSize = 20

    # 设备事件创建
    eventDeviceA1 = {}
    eventDeviceA1['CpuTime'] = 8
    eventDeviceA1['task_application'] = 'D'
    eventDeviceA1['re_Dname'] = '设备A1'
    eventDeviceA1['DeviceTime'] = 5
    eventDeviceA1['Drequest'] = True

    eventDeviceB1 = {}
    eventDeviceB1['CpuTime'] = 7
    eventDeviceB1['task_application'] = 'D'
    eventDeviceB1['re_Dname'] = '设备B1'
    eventDeviceB1['DeviceTime'] = 5
    eventDeviceB1['Drequest'] = True

    eventDeviceB11 = {}
    eventDeviceB11['CpuTime'] = 8
    eventDeviceB11['task_application'] = 'D'
    eventDeviceB11['re_Dname'] = '设备B1'
    eventDeviceB11['DeviceTime'] = 5
    eventDeviceB11['Drequest'] = True

    eventDeviceC1 = {}
    eventDeviceC1['CpuTime'] = 6
    eventDeviceC1['task_application'] = 'D'
    eventDeviceC1['re_Dname'] = '设备C1'
    eventDeviceC1['DeviceTime'] = 3
    eventDeviceC1['Drequest'] = True

    eventDeviceC12 = {}
    eventDeviceC12['CpuTime'] = 3
    eventDeviceC12['task_application'] = 'D'
    eventDeviceC12['re_Dname'] = '设备C1'
    eventDeviceC12['DeviceTime'] = 3
    eventDeviceC12['Drequest'] = True

    # 设备事件添加
    pcb1.event.append(eventDeviceA1)
    pcb1.event.append(eventDeviceB1)
    pcb1.event.append(eventDeviceC1)

    pcb2.event.append(eventDeviceB11)
    pcb2.event.append(eventDeviceC12)

    # 资源事件创建
    eventResourceR1 = {}
    eventResourceR1['CpuTime'] = 6
    eventResourceR1['task_application'] = 'R'
    eventResourceR1['ResourceTime'] = 2
    eventResourceR1['re_Resource'] = [3, 3, 3]
    eventResourceR1['Rrequest'] = True

    eventResourceR2 = {}
    eventResourceR2['CpuTime'] = 4
    eventResourceR2['task_application'] = 'R'
    eventResourceR2['ResourceTime'] = 1
    eventResourceR2['re_Resource'] = [2, 2, 2]
    eventResourceR2['Rrequest'] = True

    eventResourceR3 = {}
    eventResourceR3['CpuTime'] = 8
    eventResourceR3['task_application'] = 'R'
    eventResourceR3['ResourceTime'] = 2
    eventResourceR3['re_Resource'] = [1, 2, 3]
    eventResourceR3['Rrequest'] = True

    eventResourceR4 = {}
    eventResourceR4['CpuTime'] = 5
    eventResourceR4['task_application'] = 'R'
    eventResourceR4['ResourceTime'] = 1
    eventResourceR4['re_Resource'] = [4, 3, 2]
    eventResourceR4['Rrequest'] = True

    eventResourceR5 = {}
    eventResourceR5['CpuTime'] = 4
    eventResourceR5['task_application'] = 'R'
    eventResourceR5['ResourceTime'] = 1
    eventResourceR5['re_Resource'] = [3, 2, 3]
    eventResourceR5['Rrequest'] = True

    eventResourceR6 = {}
    eventResourceR6['CpuTime'] = 3
    eventResourceR6['task_application'] = 'R'
    eventResourceR6['ResourceTime'] = 1
    eventResourceR6['re_Resource'] = [2, 3, 2]
    eventResourceR6['Rrequest'] = True

    # 资源事件添加
    pcb2.event.append(eventResourceR1)
    pcb2.event.append(eventResourceR2)

    pcb3.event.append(eventResourceR3)
    pcb3.event.append(eventResourceR4)
    pcb3.event.append(eventResourceR5)
    pcb3.event.append(eventResourceR6)

    # 文件事件创建
    eventFileF1 = {}
    eventFileF1['CpuTime'] = 9
    eventFileF1['task_application'] = 'F'
    eventFileF1['Frequest'] = 'storage'
    eventFileF1['FileName'] = 'C\\First\\newText1.txt'
    eventFileF1['re_fSize'] = 10
    eventFileF1['Ftype'] = 0

    eventFileF2 = {}
    eventFileF2['CpuTime'] = 7
    eventFileF2['task_application'] = 'F'
    eventFileF2['Frequest'] = 'storage'
    eventFileF2['FileName'] = 'C\\First\\newText2.txt'
    eventFileF2['re_fSize'] = 10
    eventFileF2['Ftype'] = 0

    eventFileF3 = {}
    eventFileF3['CpuTime'] = 5
    eventFileF3['task_application'] = 'F'
    eventFileF3['Frequest'] = 'delete'
    eventFileF3['FileName'] = 'C\\First\\newText2.txt'
    eventFileF3['re_fSize'] = 10
    eventFileF3['Ftype'] = 0

    pcb4.event.append(eventFileF1)
    pcb4.event.append(eventFileF2)
    pcb4.event.append(eventFileF3)

    # 设置信号量
    semaphore = {'mex1': 1, 'mex2': 0}

    # 添加信号量事件
    eventSem1 = {}
    eventSem1['CpuTime'] = 8
    eventSem1['task_application'] = 'S'
    eventSem1['re_mutex'] = ['mex1']  #获取 1
    eventSem1['Srequest'] = True

    eventSemR1 = {}
    eventSemR1['CpuTime'] = 3
    eventSemR1['task_application'] = 'S'
    eventSemR1['re_mutex'] = ['mex2']  #释放 2 3
    eventSemR1['Srequest'] = False

    eventSem2 = {}
    eventSem2['CpuTime'] = 4
    eventSem2['task_application'] = 'S'
    eventSem2['re_mutex'] = ['mex2']  # 获取 2
    eventSem2['Srequest'] = True

    pcb4.Semaphore = semaphore
    pcb5.Semaphore = semaphore

    pcb4.event.append(eventSem1)
    pcb4.event.append(eventSemR1)
    pcb5.event.append(eventSem2)

    PCBList = [pcb1, pcb2, pcb3, pcb4, pcb5]
    iter = processManage('RR', PCBList)
    result = []
    while True:
        try:
            for dict in next(iter):
                result.append(dict)
            yield result
        except:
            yield result  # 暂时先这样
            break