コード例 #1
0
ファイル: commands.py プロジェクト: ekCit/OS_simulator
    def default(self, args):
        """
		Default response to user input:
		Requesting a device, killing a process or invalid command
		"""
        # User command: KILL.
        if self.lastcmd.lower()[0] is "k":
            return self.kill(self.lastcmd.lower()[1:])

        # User requests or ends a device
        device_found = False

        for dev in self.all_devices:
            if dev.is_device_name(self.lastcmd.lower()):
                device_found = True

                if self.lastcmd.islower():  # SYSTEM CALL (lowercase input)

                    # Get active process from CPU, replace with head of ready queue
                    try:
                        proc = self.cpu.dequeue()
                    except IndexError:
                        print io.nothing_in_cpu()
                        break

                    # Prompt user for and set PCB params

                    print io.sys_mode("Set system call parameters")
                    proc.set_syst_call_params()
                    proc.set_read_write_params(dev.get_dev_type())

                    if (dev.get_dev_type().lower() == "disk drive"):
                        proc.set_cylinder_params(dev.get_num_cylinders())

                    print io.sys_mode("System call parameters set")

                    # Add process to back of device queue
                    dev.enqueue(proc)

                else:  # INTERRUPT  (uppercase input)
                    # Process at head of device queue complete
                    # Remove from device queue, move to back of ready queue
                    try:
                        proc = dev.dequeue()
                        print "%s completed %s" % (dev, proc)
                        self.cpu.enqueue(proc)
                    except IndexError:
                        print io.err("{!s} queue is empty".format(dev))

        if not device_found:
            print io.invalid_command()
コード例 #2
0
ファイル: sys_gen.py プロジェクト: ekCit/OS_simulator
def generate(): 
	"""
	Generates all system device instances based on user input. 
	Returns list of all system devices.

	"""

	print io.sys_mode("System Setup")

	# Dictionary of type of devices and how many devices of each type
	system_device_types = {}

	print "For each device type, please specify the number of devices."

	for d in valid_device_types: 	
		# Add device type & how many of each type 
		system_device_types[d] = None
		system_device_types[d] = io.get_valid_int(d)

	print io.sys_mode("Initialize Disk Drive",'-')

    # List of all individual devices in system
	system_devices = []

	for dev_type, num_of_dev in system_device_types.iteritems(): 
		name_prefix = dev_type[0].lower()

		# Create new device, add to list of system_devices
		for i in range(num_of_dev):
			name = name_prefix + str(i+1)

			if (dev_type == "Disk Drive"):
				cyl = io.get_valid_int("Num of cylinders for " + name)
				system_devices.append(devices.DiskDrive(name,cyl))
			else:
				system_devices.append(devices.Device(name, dev_type))

	return system_devices
	
コード例 #3
0
ファイル: commands.py プロジェクト: ekCit/OS_simulator
    def do_s(self, args):
        """
		User input: S
		Snapshot mode: Displays processes in queue specified by user
		"""

        # Request device type from user
        print io.sys_mode("Snapshot Mode")
        print "Enter the first letter of a device type to view the queues of all devices of"
        print "that type." + "\n"
        type_to_snapshot = raw_input("Device Type >>> ").lower()

        # Show active process in CPU & processes in ready queue
        if type_to_snapshot == "r":
            self.cpu.snapshot()
            self.lts.show_job_pool()

        # Show what's in memory
        elif type_to_snapshot == "m":
            self.lts.snapshot()

        # Show processes in device
        elif type_to_snapshot in [
                d.get_dev_type()[0].lower() for d in self.all_devices
        ]:

            for dev in self.all_devices:
                if type_to_snapshot == dev.get_dev_type()[0].lower():
                    dev.snapshot()

        else:
            print io.err("Unknown device type")

        # Print system stats
        self.print_system_stats()

        print io.sys_mode("Exiting Snapshot Mode")
コード例 #4
0
ファイル: commands.py プロジェクト: ekCit/OS_simulator
 def do_h(self, args):
     """ Displays the list of valid command line inputs to user """
     print io.sys_mode("Help - Commands")
     print io.command_list()
コード例 #5
0
ファイル: commands.py プロジェクト: ekCit/OS_simulator
    def __init__(self, completekey=None):
        cmd.Cmd.__init__(self, completekey=None)
        self.prompt = " >>> "

        ## SYS GEN PHASE: Set up queues & devices in system
        self.all_devices = sys_gen.generate()

        # Set up history parameter alpha & initial bust estimate tau with valid values
        print io.sys_mode("Initialize CPU Scheduling Parameters", '-')

        set_alpha = False
        while not set_alpha:
            try:
                a = float(raw_input("History Parameter >>> "))
                if a < 0 or a > 1: raise ValueError
                self.alpha = a
                set_alpha = True
            except ValueError:
                print io.err("Please enter a number between 0 and 1")
            except OverflowError:
                print io.err("Overflow error: Please enter a shorter number")

        self.tau = io.get_valid_int("Initial Burst Estimate")

        # Set up memory size & page size
        print io.sys_mode("Initialize Memory Parameters", '-')

        # Get page & mem size. Verify page size is a power of two and a factor of memory size.
        set_size = False
        while not set_size:
            self.total_mem_size = io.get_valid_int("Total Memory Size")
            self.page_size = io.get_pow_two("Page Size")
            if self.total_mem_size % self.page_size == 0:
                set_size = True
            else:
                print io.err("Memory size must be divisible by page size")

        # Get & verify maximum process size
        set_proc_size = False
        while not set_proc_size:
            self.max_proc_size = io.get_valid_int("Maximum Process Size")
            if self.max_proc_size <= self.total_mem_size:
                set_proc_size = True
            else:
                print io.err(
                    "Maximum process size cannot be larger than total memory")

        # Set up long term scheduler. This will also set up RAM & job pool
        self.lts = LongTermScheduler(self.total_mem_size, self.page_size)

        # Set up CPU & PID
        self.cpu = devices.CPU()
        self.pid_count = 0

        # Set up system stats
        self.completed = 0
        self.total_cpu_time = 0
        self.avg_cpu_time = 0

        # Print out list of devices to console
        print io.sys_mode("System Generation Complete")
        print "Your system is now running with the following devices: "
        print io.ruler(38)
        print "{:<10}{:<28}".format("DEV NAME", "DEV TYPE")
        print io.ruler(38)
        for dev in self.all_devices:
            print "{:<10}{:<28}".format(dev.get_dev_name(), dev.get_dev_type())

        ## Now in the RUNNING PHASE
        print io.sys_mode("System running")
        print "Input a command to start a process in the system."
        print "-- Type H or h to view a list of valid commands" + "\n"