Reference no: EM132210260
Question :
Write a program in Java to evaluate different solutions to the critical sections problem in a simulated multiprogramming environment. Your program needs to read and "execute" 1-100 processes. Each process will contain several (non)critical sections. The output of the program should be a listing (table) of the process ID and it's time of completion since time 0 (to be explained later).
Your program, like a computer, needs to prep the processes at first. The program will read/open all the processes and once they're all ready to go, you begin executing process #00. This is time 0.
As a process finishes, print out the process that finished and the total time the process took to complete using the mutual exclusion method used. Since there will be two methods used, you'll have two tables to print out. See if you can catch "deadlocks": race conditions where no processes are running anymore. Hint: they may not occur! Try and force one by creating process files with values that will result in one.
For this assignment, a process will be a file of the name pXX.txt where XX is a two digit number ranging from 00 to 99. These represent process IDs. Your program needs to support up to 100 processes. The file will primarily contain nothing but a list of positive integers, one integer per line. Each integer represents milliseconds (i.e. 500 == 0.5 seconds). Also in this file may be comments. Comment lines have, optionally, tabs/spaces followed by a hash/pound symbol '#'.
Example:
# Process #00 500 # first critical section 1500 200 15 5000 # End of Process #00
Since processes typically have "setup" at their beginning, the first integer will represent a non-critical region. The second integer will be a critical region. The third, a non-critical, then 4th critical, etc. "Odd lines" are non-critical regions, "even lines" are critical regions. Note: "" are around "odd" and "even" because the process file may have comments in them!! Process files may have at most 10000 integers with each integer being a positive value between 1 and MAXINT where integers are 4 bytes.
Have your "CPU" give a 500ms time slice to a process before switching it out and moving to another process. when a process' time slice is up, move on to the next PID that has not completed. For example, if you initially had PIDs from 00 to 15 but 14 has finished and the CPU is currently on 13, when 13's time slice is done, move on to PID 15 (since 14 has finished).
The program should look for process files in the current directory. Read and account for process files sequentially, starting at 00, until you don't find one. For example, if file p01.txt through p99.txt exist, running your program should quit almost immediately because p00.txt wasn't found. Another example, if p00.txt through p99.txt all exist EXCEPT for p10.txt, your program should only process p00.txt through p09.txt since p10.txt won't be found.