Question: Programming Questions (50 marks In this programming question, you need to build a program that simulates CPU (Central Processing Unit) scheduling for executing porcesses/jobs (these

 Programming Questions (50 marks In this programming question, you need tobuild a program that simulates CPU (Central Processing Unit) scheduling for executingporcesses/jobs (these names wil be used interchangably as they have the same

Programming Questions (50 marks In this programming question, you need to build a program that simulates CPU (Central Processing Unit) scheduling for executing porcesses/jobs (these names wil be used interchangably as they have the same meaning) on a computer system. You are going to use a priority queue to schedule the CPU jobs for the operating system. As a quick idea of what you need to do, the jobs, which are recorded in an initial array, are entred into a priority queue. The program will then keep looping, where each iteration will correspond to a time slice of the CPU where one of the jobs is partially executed, until the priroty queue is empty (which indicates that all jobs have been completed). Figure 1 illustrates the basic operation of the system. The fine details are provided below Exit Job Yes Finished Jk Priority Queue Figure 1: Basic Simulation of the System The input to the program is an array of jobs, called jobsInputArray, which holds a set of jobs, each consisting of jobName (String type) indicating the name of that process/job, jobLength (int type) indicating the needed CPU cycles for this job to terminate, currentJobLength (int type) indicating the remaining length of the job at any given time, jobPriority (int type) indicating the initial priority of this job, finalPriority (int type) indicating the final priority of the job at terminaion time, entryTime (long type) indicating the time this job entered the priority queue, endTime (long type) indicating when this job finally terminated, and waitTime (long type) indicating the total amount of wait time a process had to incure from the time it entered the queue until it terminates. All jobs must first be intered in the priority queue. Each insetion takes one unit of time, consequently the entryTime of a job must be set to that time. For instance, when the first job, J1, is inserted, its entryTime is recorded as 1. When J6 is insetred, its entryTime must be set as 6, since this is how much it took before this job is inserted, and so on. Each job has a length (jobLength), which indicates how much time/CPU cycles the job needs to be allcated the CPU (served by the CPU) before it is finally terminated. The length of a job is always between 1 and 70 cycles. Additionally, each job has an initial priority jobPriority), and a final prioirty (finalPriority), each is a value between 1 (highest priority) and 40 (lowest priority), inclusive. Your simulator should process the jobs from the priority queue based on the current priority of each job, and with First-Come-First-Served (FCFS) basis as a tie breaker in case these current priorities are the same. That is, if two jobs have different priorities, then the job with the higher priority will be executed first; otherwise, jobs with the same priority will be executed based on which one was first entered the queue. Your simulator must somehow keep track of that to enforce this rule. Additionally, there are also other important rules that the simulator must implement; particularly in relation to starvation avoidance, as detailed below. To avoid low-priority processes from being starved for an unreasonable amount of time, the simulator must check periodically for starved jobs and change their current priorities to the highest priority, so they can finally execute. This is done periodically each time a total of 30 processes are terminated. That is, each time 30 processes are finished, the simulator must search the queue for the oldest job (recall jobs have an entry time field on them) that has NEVER been executed, then changes the current priority of that job to 1, adjusts its location in the queue if needed (depending on your implementation!), effectively resulting in this job being executed. Once the current priority is changed, it is kept as such until the job terminates. By repeating this process periodically (each time 30 jobs are finished), starvation of low priority jobs is mitigated. Programming Questions (50 marks In this programming question, you need to build a program that simulates CPU (Central Processing Unit) scheduling for executing porcesses/jobs (these names wil be used interchangably as they have the same meaning) on a computer system. You are going to use a priority queue to schedule the CPU jobs for the operating system. As a quick idea of what you need to do, the jobs, which are recorded in an initial array, are entred into a priority queue. The program will then keep looping, where each iteration will correspond to a time slice of the CPU where one of the jobs is partially executed, until the priroty queue is empty (which indicates that all jobs have been completed). Figure 1 illustrates the basic operation of the system. The fine details are provided below Exit Job Yes Finished Jk Priority Queue Figure 1: Basic Simulation of the System The input to the program is an array of jobs, called jobsInputArray, which holds a set of jobs, each consisting of jobName (String type) indicating the name of that process/job, jobLength (int type) indicating the needed CPU cycles for this job to terminate, currentJobLength (int type) indicating the remaining length of the job at any given time, jobPriority (int type) indicating the initial priority of this job, finalPriority (int type) indicating the final priority of the job at terminaion time, entryTime (long type) indicating the time this job entered the priority queue, endTime (long type) indicating when this job finally terminated, and waitTime (long type) indicating the total amount of wait time a process had to incure from the time it entered the queue until it terminates. All jobs must first be intered in the priority queue. Each insetion takes one unit of time, consequently the entryTime of a job must be set to that time. For instance, when the first job, J1, is inserted, its entryTime is recorded as 1. When J6 is insetred, its entryTime must be set as 6, since this is how much it took before this job is inserted, and so on. Each job has a length (jobLength), which indicates how much time/CPU cycles the job needs to be allcated the CPU (served by the CPU) before it is finally terminated. The length of a job is always between 1 and 70 cycles. Additionally, each job has an initial priority jobPriority), and a final prioirty (finalPriority), each is a value between 1 (highest priority) and 40 (lowest priority), inclusive. Your simulator should process the jobs from the priority queue based on the current priority of each job, and with First-Come-First-Served (FCFS) basis as a tie breaker in case these current priorities are the same. That is, if two jobs have different priorities, then the job with the higher priority will be executed first; otherwise, jobs with the same priority will be executed based on which one was first entered the queue. Your simulator must somehow keep track of that to enforce this rule. Additionally, there are also other important rules that the simulator must implement; particularly in relation to starvation avoidance, as detailed below. To avoid low-priority processes from being starved for an unreasonable amount of time, the simulator must check periodically for starved jobs and change their current priorities to the highest priority, so they can finally execute. This is done periodically each time a total of 30 processes are terminated. That is, each time 30 processes are finished, the simulator must search the queue for the oldest job (recall jobs have an entry time field on them) that has NEVER been executed, then changes the current priority of that job to 1, adjusts its location in the queue if needed (depending on your implementation!), effectively resulting in this job being executed. Once the current priority is changed, it is kept as such until the job terminates. By repeating this process periodically (each time 30 jobs are finished), starvation of low priority jobs is mitigated

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!