-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Operating system to store processes Queue
- Loading branch information
1 parent
2327b30
commit c3765e4
Showing
2 changed files
with
37 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,41 @@ | ||
import random | ||
from datetime import datetime, timedelta | ||
from classes import PCB, Scheduler | ||
from classes import PCB, Scheduler, OS | ||
import logging | ||
logging.basicConfig(filename = 'output.log', level=logging.DEBUG, format='%(message)s') | ||
|
||
def processes_creator(scheduler): | ||
def processes_creator(operating_system): | ||
"""Generates random processes until there are 4 different priorities and at least 18 different processes created. | ||
Args: | ||
`scheduler`: Scheduler receiving and organizing order processes according to their priority and creation time. | ||
`operating_system`: operating_system receiving and managing processes. | ||
""" | ||
end_address = 9999 | ||
date_time = datetime.now().replace(microsecond=0) | ||
number_of_processes = 0 | ||
|
||
while len(scheduler.sorted_queues) != 4 or number_of_processes < 18: | ||
while len(operating_system.sorted_queues) != 4 or number_of_processes < 18: | ||
name = 'PROCESS {:02d}'.format(number_of_processes + 1) | ||
priority = random.randint(1, 4) | ||
date_time += timedelta(minutes=1) | ||
init_address = end_address + 1 | ||
end_address = init_address + random.randint(1, 20) | ||
remaining_time = random.randint(2, 18) | ||
process = PCB(name, priority, date_time, init_address, end_address, remaining_time) | ||
scheduler.schedule_process(process) | ||
operating_system.add_process(process) | ||
number_of_processes += 1 | ||
|
||
def main(): | ||
operating_system = OS() | ||
scheduler = Scheduler() | ||
|
||
time_unit = 0 | ||
|
||
processes_creator(scheduler) | ||
processes_creator(operating_system) | ||
|
||
logging.info("SCHEDULER:") | ||
logging.info(scheduler) | ||
logging.info("OPERATING SYSTEM:") | ||
logging.info(operating_system) | ||
|
||
scheduler.round_robin(time_unit) | ||
scheduler.round_robin(time_unit, operating_system) | ||
|
||
main() |