Question

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.

Your task is to write a job scheduler that decides, for each second, what job should be run. The job that is available that has the highest priority value should be scheduled for the next second (ties can be broken arbitrarily). The central data structure to use a priority queue. You should implement your own priority queue, rather than rely on a built-in data structure.

Notes:

The list of jobs will first need to be sorted by arrival time.

The simulation begins at time 0 and runs until all jobs are finished.

At the beginning of each second:

  1. Check if new jobs need to be added to the priority queue.

  2. If the queue is non-empty, get the top priority job and run it for 1 second. If it finishes remove it, otherwise put it back in the queue.

Output:

Your program should print out which job is running each second. You should also compute the waiting time and total execution time for each job. The waiting time is the time the job actually starts versus when it was first available. The total execution time is the number of seconds that it takes to finish the job once it begins (this will be greater than or equal to its duration). Some points will be awarded for nicely-formatted output.

Example: suppose a job arrives at time 10s with duration 10s, starts at time 15s and finishes at time 30s. Then the waiting time is 5s, and the execution time is 15s.

Your program should run from the command line:

java -jar JobScheduler.jar input.txt

Please code this in Java.

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

IF YOU HAVE ANY DOUBTS COMMENT BELOW I WILL THERE TO HELP YOU

ANSWER:

CODE:

  1. Languaged used :- PYTHON2
  2. Compile and run :- python2 filename.py
  3. input :- input.txt
  4. Output :- output.txt

Code :-

  • #sort according to priority
    def sortPriority(l, n) :
    for i in range(n) :
    for j in range(n) :
    if l[i][1] > l[j][1]:
    swap = l[i]
    l[i] = l[j]
    l[j] = swap
    return l

    #sort according to arrival time
    def sortArrival(l, n) :
    for i in range(n) :
    for j in range(n) :
    if l[i][2] < l[j][2] or (l[i][2] == l[j][2] and l[i][1] > l[j][1]):
    swap = l[i]
    l[i] = l[j]
    l[j] = swap
    return l

    #get tp of the queue
    def topQueue(l) :
    if len(l) != 0 :
    return l.pop(0)
    else :
    return []

    #add eleemt inot the queue
    def addQueue(x, l) :
    l.append(x)
    #sort any according to priority
    return sortPriority(l, len(l))

    #main program starts
    if __name__ == '__main__' :
    f = open("input.txt","r")

    l, tmp, job = [], [], []
    for i in f.readlines() :
    r = []
    r = map(int, i.split(" "))
    r.append(0)
    r.append(0)
    r.append(0)
    l.append(r)

    f.close()

    f = open("output.txt", "w")
    l = sortArrival (l, len(l))
    f.write("Job Priority Arrival Total Waiting Completion ")
    for i in range(len(l)) :
    f.write(str(l[i][0])+" "+str(l[i][1])+" "+str(l[i][2])+" "+str(l[i][3])+" "+str(l[i][4])+" "+str(l[i][5])+" ")
      

    i = 0
    while len(job) != len(l) :
    n = len(l)
    for j in range(n) :
    if l[j][2] == i :
    l[j][4] = i
    addQueue(l[j], tmp)
    print ("At"+" "+str(i)+" sec job"+" "+str(l[j][0])+" "+"added")
      
      
    top = topQueue(tmp)
    if top != [] and top[6] == 0 :
    top[4] = i-top[4]
    top[6] = 1
    if top != [] :
    print ("Job "+str(top[0])+" is in the queue")
    if top[3] == 0 :
    top[5] = i
    job.append(top)
    else :
    top[3] -= 1
    if top[3] == 0 :
    top[5] = i
    job.append(top)
    else :
    tmp = addQueue(top, tmp)
    i += 1
      

    f.write(" ")
    f.write("Job Priority Arrival Total Waiting Completion ")
    for i in range(len(job)) :
    f.write(str(job[i][0])+" "+str(job[i][1])+" "+str(job[i][2])+" "+str(job[i][3])+" "+str(job[i][4])+" "+str(job[i][5])+" ")
    f.close()
    print job

  • Input :-

  • 1 1 10 100
    5 2 20 50
    8 4 5 100

Add a comment
Know the answer?
Add Answer to:
Overview: In this lab, you will write a program called JobScheduler; it should take a single...
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
  • Write a C program that should run on Linux platform using gcc compiler. You are required...

    Write a C program that should run on Linux platform using gcc compiler. You are required to simulate threads creation and termination behavior by using POSIX threads library. Input: In the main program, first take the value for total number of threads and then ask user to provide the arrival time and CPU time (i.e. running time) for each thread. Output: Simulate the behavior of threads arrival, working and termination at a specific time interval (i.e. 500ms). Requirements: i. Name...

  • Description In this homework, you are asked to implement a multithreaded program that will allow ...

    Description In this homework, you are asked to implement a multithreaded program that will allow us to measure the performance (i.e, CPU utilization, Throughput, Turnaround time, and Waiting time in Ready Queue) of the four basic CPU scheduling algorithms (namely, FIFO, SJE PR, and RR). Your program will be emulating/simulating the processes whose priority, sequence of CPU burst time(ms) and I'O burst time(ms) will be given in an input file. Assume that all scheduling algorithms except RR will be non-preemptive,...

  • I need help with a java program Write a program Enigma that takes a single String...

    I need help with a java program Write a program Enigma that takes a single String as a command line argument. Enigma should read the file specified by the String argument, add 5 to each byte, and leave the altered data values in a file whose name is the command line argument. Note that this "updating in place" is the most difficult part of this lab: java Enigma sophie.dat should read file sophie.dat, and upon completion, leave the modified data...

  • 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...

  • Java coding. Create a class called Printer and a class called Job that will simulate a...

    Java coding. Create a class called Printer and a class called Job that will simulate a computer printer. The printer should store a queue of Job objects until they are printed. Each Job should consist of a title and the number of pages the job contains. The printer should also store the number of jobs it can print per minute. The class should include methods to add jobs and print jobs. The method that prints a job should return the...

  • 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...

  • In C write a program that must accept one argument from the command line. The argument...

    In C write a program that must accept one argument from the command line. The argument is the name of the file containing the processes (for example: processes.csv).This file is comma-separated with three columns (process ID, arrival time and burst time) with each row for an individual process. You can assume that this file will have a maximum of 10 processes. For example Input: processes.csv ProcessID,Arrival Time,Burst Time 0,1,3 1,0,5 2,9,8 3,10,6 Where the first element is processes, the second...

  • You will write a single java program called MadLibs. java.

    You will write a single java program called MadLibs. java. This file will hold and allow access to the values needed to handle the details for a "MadLibs" game. This class will not contain a maino method. It will not ask the user for any input, nor will it display (via System.out.print/In()) information to the user. The job of this class is to manage information, not to interact with the user.I am providing a MadLibsDriver.java e^{*} program that you can...

  • Solve it for java Question Remember: You will need to read this assignment many times to...

    Solve it for java Question Remember: You will need to read this assignment many times to understand all the details of the you need to write. program Goal: The purp0se of this assignment is to write a Java program that models an elevator, where the elevator itself is a stack of people on the elevator and people wait in queues on each floor to get on the elevator. Scenario: A hospital in a block of old buildings has a nearly-antique...

  • Write a function template that receives a priority queue and an output stream as parameters. Lab 48 Due Date: See Blackboard Source File: /2336/48/1ab48.cpp Input: Output:under control of main functio...

    Write a function template that receives a priority queue and an output stream as parameters. Lab 48 Due Date: See Blackboard Source File: /2336/48/1ab48.cpp Input: Output:under control of main function Waol under control of main function Write a function template that receives a priority queue and an output stream as parameters. The function determines the distribution of the elements in the priority queue; that is, the function counts the number of occurrences of each element. The format of the output...

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