Question

java  Operating System Scheduler Two scheduling strategies for an operating system scheduler are first come first serve...

java  Operating System Scheduler

Two scheduling strategies for an operating system scheduler are first come first serve (FCFS) and fixed priority pre-emptive scheduling (FPPS). Since queues operate on a first come first serve basis, FCFS is implemented using a queue. Similarly, FPPS is implemented using a priority queue.

The operating system scheduler simulation is already provided for you. To use it you simply need to modify the main method to run the simulator using either the LinkedListQueue or the PriorityQueue.

Run the simulator a few times with each type of queue. Answer the following four questions about your experiments in a plain text file called scheduler.txt.

1. What are differences in how the jobs are managed between FCFS and FPPS?

2. What is are the advantages of FCFS over FPPS and vice versa?

3. What potential problems do you see happening if you were using an operating system with an FCFS scheduler?

4. What potential problems do you see happening if you were using an operating system with an FPPS scheduler?

public class Simulation
{
private Queue scheduler;
  
private static final int DEFAULT_TIME = 100;
private static final int NUMBER_OF_JOBS = 10;
private static final int PRIORITY_LEVELS = 3;
private static final int MAX_DURATION = 1000;
  
/**
* Creates an Operating System Simulator to test a given scheduler.
*
* @param scheduler The scheduler to test. The scheduler should use the Queue
* interface.
*/
public Simulation(Queue scheduler)
{
this.scheduler = scheduler;
}
  
/**
* Runs the simulator by creating a certain number of Jobs and then running
* until all the Jobs are completed. It outputs a progress report at each time
* it retrieves a new Job from the scheduler and runs it. By default it runs
* each Job for 100 milliseconds at a time, however, if a Job finishes before
* that time has elapsed the remaining time is given to the next Job.
*/
public void run()
{
if (scheduler == null)
{
return;
}
  
Random generator = new Random();
System.out.println("Creating jobs...");
for (int i = 0; i < NUMBER_OF_JOBS; i ++)
{
Job temp = new Job(generator.nextInt(PRIORITY_LEVELS),
generator.nextInt(MAX_DURATION));
scheduler.enqueue(temp);
System.out.println(temp);
}
  
System.out.println();
System.out.println("Running jobs...");
int time = DEFAULT_TIME;
while (!scheduler.isEmpty())
{
Job active = scheduler.dequeue();
  
System.out.println("Running Job " + active.getId() + " for " + time + " milliseconds..");
if (active.getDuration() >= time)
{
active.run(time);
time = DEFAULT_TIME;
}
else
{
time = DEFAULT_TIME + time - active.getDuration();
active.run(active.getDuration());
}
System.out.print("..." + active);   
  
if (active.getDuration() > 0)
{
scheduler.enqueue(active);
System.out.println();
}
else
{
System.out.println(" COMPLETE!");
}
}
}
  
/**
* The main method creates the scheduler and the operating system simulator
* on which to test it. It also runs the simulator. Modify the main method
* in order to change the scheduler and compare the results.
*/
public static void main(String[] args)
{
Queue jobs = null; // Replace null with the queue you want to test
Simulation simulator = new Simulation(jobs);
simulator.run();
}
}

class Job

public class Job
{
/**
* This constant indicates that an application is the owner of the job.
*/
public static final int APPLICATION = 0;
  
/**
* This constant indicates that the user is the owner of the job.
*/
public static final int USER = 1;
  
/**
* This constant indicates that the operating system is the owner of the job.
*/
public static final int SYSTEM = 2;
  
private int owner;
private int duration;
private int id;
  
private static int currentId = 0;
  
/**
* The constructor for Job initializes its three instance variables. It gets
* the owner and the duration (in milliseconds) from the user and assigns
* a unique id to the Job.
*
* @param owner Either 0, 1 or 2 inidicating who created the Job.
* @param duration The number of milliseconds the Job must run until completion.
*/
public Job(int owner, int duration)
{
this.owner = owner;
this.duration = duration;
this.id = currentId ++;
}
  
/**
* Gets the unique id of the Job.
*
* @return An integer id unique to this Job.
*/
public int getId()
{
return this.id;
}
  
/**
* Gets the owner of the Job.
*
* @return 0, 1 or 2 indicating the owner, an application, the user or
* the system respectively, of the Job.
*/
public int getOwner()
{
return this.owner;
}
  
/**
* Gets the remaining duration, in milliseconds, of the Job.
*
* @return An integer containing the remaining duration of the Job.
*/
public int getDuration()
{
return this.duration;
}
  
/**
* Runs the job for a certain number of milliseconds.
*
* @param time An integer containing the number of milliseconds that the
* job should be run.
*/
public void run(int time)
{
this.duration -= time;
  
if (this.duration < 0)
{
this.duration = 0;
}
  
try
{
if (time > duration)
{
Thread.sleep(time);
}
else
{
Thread.sleep(duration);
}
}
catch (Exception e)
{
// Do nothing
}
}
  
/**
* Determines if two Jobs are equal by comparing their unique ids.
*
* @param other The Job to compare with this Job.
* @return True if the two Jobs have the same id, false otherwise.
*/
public boolean equals(Job other)
{
return this.getId() == other.getId();
}
  
/**
* Produces a String representation of the Job.
*
* @return A String representation of the job.
*/
public String toString()
{
StringBuffer result = new StringBuffer();
  
result.append("Job ");
result.append(getId());
  
result.append(" owned by ");
switch(getOwner())
{
case SYSTEM: result.append("the system "); break;
case USER: result.append("the user "); break;
case APPLICATION: result.append("an application "); break;
default: result.append(" ERROR "); break;
}
  
result.append("has ");
result.append(duration);
result.append(" microseconds remaining;");
  
return result.toString();
}
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

1. In FCFS jobs are put into normal QUEUE data structure which itself follows FCFS policy. Irespective of the jobs' priority in the queue, job that is oldest in the queue will be executed.
But in FPPS jobs are put into a PRIORITY QUEUE data structure which dequeues an item based on some predefined priority. In this case job that have highest priority in the queue will be executed first irespective of its age in the queue.

2. Advantages of FCFS:
   a. No starvation
   b. Simple data structure

Advantages of FPPS:
   a. Can reduce avg waiting time
   b. Known for improving throughput
   c. System task and other urgent jobs can be easily handled

3. FCFS have certain problem:
   a. Shorter job or Urgent job have to wait quite long in the queue
   b. Can increase the avg waiting time if there are more shorter job than longer jobs

4. FPPS have certain problem:
   a. Complex data structure
   b. Can cause starvation of lower priority jobs
   c. Job dispatcher may consume little more time since dequeue operation of Priority queue is not always of complexity O(1)

Add a comment
Know the answer?
Add Answer to:
java  Operating System Scheduler Two scheduling strategies for an operating system scheduler are first come first serve...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please help me create this CLI CPU Scheduling Simulator in java: First Come First Serve (FCFS)...

    Please help me create this CLI CPU Scheduling Simulator in java: First Come First Serve (FCFS) Round Robin (RR) Process information The process information will be read from an input file. The format is: pid arrival_time burst_time All of fields are integer type where: pid is a unique numeric process ID arrival_time is the time when the task arrives in the unit of milliseconds burst_time the is the CPU time requested by a task, in the unit of milliseconds The...

  • Implement a greedy strategy in JAVA which takes in a list of job object ( each...

    Implement a greedy strategy in JAVA which takes in a list of job object ( each job object consist of Job id (integer) , startTime (float) and endTime(float)) and outputs a list of non-conflicting jobs according to their start time. (Implement the given method provided in the code). Example of Input: id startTime endTime 1 4 7 2 3 5 3 7 9 CODE import java.util.Scanner; import java.util.List; import java.util.ArrayList; import java.io.InputStream; public class JobScheduling { public static final Strategy...

  • This is an additional assignment from the chapter on the Java Collections Framework. Suppose you buy...

    This is an additional assignment from the chapter on the Java Collections Framework. Suppose you buy 100 shares of a stock at $12 per share, then another 100 at $10 per share, then you sell 150 shares at $15. You have to pay taxes on the gain, but exactly what is the gain? In the United States, the FIFO rule holds: You first sell all shares of the first batch for a profit of $300, then 50 of the shares...

  • COP3337 Assignment 10 This is an additional assignment from the chapter on the Java Collections Framework....

    COP3337 Assignment 10 This is an additional assignment from the chapter on the Java Collections Framework. Suppose you buy 100 shares of a stock at $12 per share, then another 100 at $10 per share, then you sell 150 shares at $15. You have to pay taxes on the gain, but exactly what is the gain? In the United States, the FIFO rule holds: You first sell all shares of the first batch for a profit of $300, then 50...

  • import java.util.Iterator; import java.util.LinkedList; import java.util.TreeMap; import java.util.ArrayList; public class MultiValuedTreeMap<K, V> extends TreeMap<K, LinkedList<V>> implements...

    import java.util.Iterator; import java.util.LinkedList; import java.util.TreeMap; import java.util.ArrayList; public class MultiValuedTreeMap<K, V> extends TreeMap<K, LinkedList<V>> implements Iterable<Pair<K, V>> {    private static final long serialVersionUID = -6229569372944782075L;       public void add(K k, V v) {        if (!containsKey(k)) { put(k, new LinkedList<V>()); } get(k).add(v);    }       public V removeFirst(K k) {               if (!containsKey(k)) { return null;        } V value = get(k).removeFirst(); if (get(k).isEmpty()) { super.remove(k); } return value;    }...

  • (Java Coding) Game1: You win if one get one six in four rolls of one dice. (To be Simulated 1,000,000 times) Game2: You win if one get double sixes in twenty four rolls of two dice. (To be simulated 1...

    (Java Coding) Game1: You win if one get one six in four rolls of one dice. (To be Simulated 1,000,000 times) Game2: You win if one get double sixes in twenty four rolls of two dice. (To be simulated 1,000,000 times) Given below that the class die, oddstester, and gameSimulator(partially complete and the bold missing parts need to be done), need to find the probability of winning game 1 and 2 (after the 1 million plays) hence the getWins and...

  • Overview: In this lab, you will write a program called JobScheduler; it should take a single...

    Overview: In this lab, you will write a program called JobScheduler; it should take a single input file as a command-line argument. Each line in the input file has the following format: <job #> <priority> <arrival time (sec)> <duration (sec)> e.g. a file might contain: 1 3 10 100 5 2 20 50 8 4 5 100 (all values will be positive integers) These jobs might represent computer programs (or threads) that need to be run by the operating system....

  • Language is Java, any help is appreciated. Thank you! WHERE TO START FROM: import java.util.ArrayList; //PartTest.java...

    Language is Java, any help is appreciated. Thank you! WHERE TO START FROM: import java.util.ArrayList; //PartTest.java //package simple; public class PartTest { public static void main(String[] args) { ArrayList<ExpendablePart> system=new ArrayList<ExpendablePart>();   // creating Part Object Part part1 = new ExpendablePart("Last, First"); part1.setNumber("AX-34R"); part1.setNcage("MN34R"); part1.setNiin("ABCD-RF-WDE-KLJM"); // printing information System.out.println(part1.toString());       //Create a part2 object of class Part Part part2=new ConsumablePart("Widget, purple"); part2.setNumber("12345"); part2.setNcage("OU812"); part2.setNiin("1234-12-123-1234");    // printing information System.out.println(part2.toString());    //checking equality of two Part class objects if(part1.equals(part2)) System.out.println("part1 and...

  • Define a toString method in Post and override it in EventPost. EventPost Class: /** * This...

    Define a toString method in Post and override it in EventPost. EventPost Class: /** * This class stores information about a post in a social network news feed. * The main part of the post consists of events. * Other data, such as author and type of event, are also stored. * * @author Matthieu Bourbeau * @version (1.0) March 12, 2020 */ public class EventPost extends Post { // instance variables - replace the example below with your own...

  • Java Programming Question

    After pillaging for a few weeks with our new cargo bay upgrade, we decide to branch out into a new sector of space to explore and hopefully find new targets. We travel to the next star system over, another low-security sector. After exploring the new star system for a few hours, we are hailed by a strange vessel. He sends us a message stating that he is a traveling merchant looking to purchase goods, and asks us if we would...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT