Question: make sure to write a full code that solve this task and test it after write the code you will simulate a CPU scheduling system

make sure to write a full code that solve this task and test it after write the code
you will simulate a CPU scheduling system combined with deadlock detection and recovery. The system consists of a single CPU core and several resource types, with only one instance of each resource type. The goal is to simulate the execution of processes, apply CPU scheduling, detect deadlocks, and recover from them.
Input format:
Your program will take as input a text file containing a list of processes. Each line in the file represents a process and has the following format:
[PID][Arrival Time][Priority][Sequence of CPU and IO bursts]
Each process must start and finish with a CPU burst. Within CPU bursts, processes can request or release resources. For example, the input file might look like this:
001 CPU {R[1],50, F[1]}
151 CPU {20} IO{30} CPU{20, R[2],30, F[2],10}
Explanation:
Process 0(PID =0) arrives at time0, has a priority of1, and consists of one CPU burst. During this burst, it requests resource 1(R[1]), executes for 50 time units, then releases resource 1(F[1]) and terminates.
Process 1(PID =1) arrives at time5, also with priority1, and consists of two CPU bursts and one IO burst:
The first CPU burst lasts for 20 units, followed by an IO burst lasting 30 units. The second CPU burst executes for 20 units, after which it requests resource 2(R[2]), executes for 30 units, releases resource 2(F[2]), and finally finishes with 10 more CPU units.
Your Task:
- Simulate CPU Scheduling: Implement priority scheduling algorithm with round robin . The simulation should continue until all the processes in the input file terminate.
- Deadlock Detection and Recovery: Implement an appropriate deadlock detection algorithm to monitor the system status and identify deadlock situations. If a deadlock is detected, implement a deadlock recovery strategy of your choice (e.g., process termination, resource preemption).
- At the end of simulation, your program must show the Gantt chart representing the timeline of process execution, average waiting time, and average turnaround time for all processes. Also report the detected deadlock states and how recovery was handled.
Remarks:
- Testing: Start with simple input files to test your program and ensure its correctness. Gradually test with more complex scenarios.
- Context Switching: Assume that the context switch time is negligible and can be ignored in the simulation.
- I/O Simulation: When a process finishes its CPU burst, it moves to the I/O queue for the duration of its I/O burst. Processes can perform I/O simultaneously and do not wait for each other. When the I/O burst is finished, the process goes back to the ready queue.
- Resource Requests: If a process requests a resource that is currently held by another process, it should be moved to thewaiting queueuntil the resource becomes available. The process will remain in the waiting queue until the requested resource is released by the holding process.
- Time Representation: Use a simple time counter for the simulation. The time units do not need to have any real-world meaning, but the simulation should track time correctly.
- Single-threaded Implementation: You can implement the simulation in a single-threaded program. If you choose to implement it usingmultithreadingormultiprocessing, ensure you handle synchronization correctly.

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 Programming Questions!