-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess.py
More file actions
42 lines (34 loc) · 1.82 KB
/
process.py
File metadata and controls
42 lines (34 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from enum import Enum
# DEFINE THE POSSIBLE STATES OF A PROCESS
class ProcessState(Enum):
NEW = "New" # Process has been created
READY = "Ready" # Process is ready to be executed
RUNNING = "Running" # Process is in execution
BLOCKED = "Blocked" # The execution of the process is stopped
TERMINATED = "Terminated" # Process has completed
ZOMBIE = "Zombie" # State to represent zombie mode
BLOCKED_SUSPENDED = "Blocked Suspended" # Process that has to wait to be executed
READY_SUSPENDED = "Ready Suspended" # Process that is getting ready to be executed
# CLASS TO REPRESENT THE OS PROCESS
class Process:
# MAPPING PRIORITY LEVELS TO EXECUTION TIMES (LONGER EXECUTION TIMES FOR LOWER PRIORITIES)
PRIORITY_EXECUTION_TIMES = {
'High': 100, # High priority gets the shortest execution time
'Medium High': 200, # Medium High priority gets more time
'Medium Low': 300, # Medium Low priority gets even more time
'Low': 400, # Low priority gets the longest execution time
}
def __init__(self, pid, priority):
"""
Initialize a new process with a given priority.
:param pid: Process ID
:param priority: Priority level ('High', 'Medium High', 'Medium Low', 'Low')
"""
self.pid = pid
self.state = ProcessState.NEW # Start in the NEW state
self.priority = priority # Priority of the process
# Assign execution time based on the priority level
self.execution_time = Process.PRIORITY_EXECUTION_TIMES[priority]
self.progress = 0 # Progress starts at 0
self.manual_state = None # No manual state change initially
self.pre_zombie_state = None # To track the state before entering Zombie mode