Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program to simulate job scheduling in an operating system. In this simulation, we will have jobs which need to be run on a

Write a program to simulate job scheduling in an operating system. In this simulation, we will have jobs which need to be run on a processor to complete. Each job will take a varying number of clock cycles to execute. When the required number of clock cycles has passed, the job is removed from the processor and is considered to be completed. At the start of each clock cycle, the processor checks if it is currently running a job. If it is, it spends another cycle working on that job. If the processor is not running a job, it gets a job from the input queue and begins running it. The input queue contains all jobs which need to be executed. Jobs have priority as well. A jobs priority is represented by an integer value between 1 and 4, where 1 is the highest priority and 4 is the lowest priority. At the start of each clock cycle, the processor checks the first job in the input queue. If that job has a lower priority that the job currently being run by the processor (or the processor is not currently running a job), then the system behaves as described in the previous paragraph. But if the first job in the input queue has a higher priority than job the processor is currently running, then the job from the queue is run by the processor. The job which was being run by the processor is pushed onto the active job stack. Jobs placed on the active job stack keep all the work that had been completed while being run by the processor. (So if a job needs to run for 5 clock cycles to complete, and had run for 2 clock cycles before being placed on the active job stack, it would only need to be run for 3 more clock cycles before being completed) At the end of each clock cycle, we determine if the current job has been run for the necessary number of clock cycles. If it has, the job is completed and we remove it from the processor. Once removed, we pop the top element off the active job stack and place it back on the processor. Once placed the clock cycle ends and the process starts over from the start. The simulation is considered complete when the input queue is empty, the active job stack is empty, and there is no job being run by the processor. input To create this simulation in Java, you will create a class named OperatingSystem.java which contains a method named: public static ArrayList JobScheduler(ArrayList input) The JobScheduler method takes a single parameter, an ArrayList of type Job. The Job object is provided. A Job has five instance variables: jobNumber requiredExecutionTime givenExecutionTime entryTime priority along with getters and setters for these instance variables. JobScheduler should take this ArrayList of Jobs and place them into Queue of type job which represents our input queue. It should then implement the described simulation. JobScheduler should also implement an ArrayList of Strings for storing the results of the simulation. When a job is completed, the following String should be added to the results ArrayList: "At CPU time " + cpuTime + " Job Number " + finishedJob.getJobNumber() + " finished processing" where cpuTime is the current cycle of the CPU and finishedJob is the job which has just completed. When your simulation is completed, JobScheduler should return the results ArrayList. Also included with this lab is implementations of both Stack and Queue. You should use these implementations for the input queue and the active job stack. When you have completed your implementation of OperatingSystem.java, use the provided test cases to test your work. When complete, submit your OperatingSystem.java to Blackbaord. If you create a main method for your own testing purposes, you dont need to include it in your submission. As an example, if your simulator was given an ArrayList containing two jobs, the first job requiring six clock cycles to run and having a priority of 3 and the second job requiring seven clock cycles to run and having a priority of 2, the expected output of your simulator would be: At CPU time 8 Job Number 2 finished processing At CPU time 13 Job Number 1 finished processing Here is a suggested algorithm to get you started on your program (note that this is merely a starting point; it isnt necessarily complete!) initial clock, queue, stack, etc. place all jobs into the inputQueue while all jobs are not completed if inputQueue is not empty get first item from inputQueue and check if we can place it on the processor if we need to place the current job on the processor onto the active job stack, do so endif increment the execution time of the current job by one if the current job has been given all the clock cycles needed to finish remove job from processor and simulation place job from active job stack onto processor if applicable endif increment clock endwhile

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Online Market Research Cost Effective Searching Of The Internet And Online Databases

Authors: John F. Lescher

1st Edition

0201489295, 978-0201489293

More Books

Students also viewed these Databases questions

Question

What are the limitations of forward markets?

Answered: 1 week ago