DESCRIPTION
In a multiprogramming environment, resources are shared among all processes.
Resources could be memory, CPU, printers, files , etc..
OS designers use simulation method to calculate and/or observe resource
allocation and deadlock prevention.
You ( as an OS designer ) are asked to write a time driven simulation
program in a language of your choice* that can perform the following tasks:
1. Reads all the information from a file called firstname_lastname.in,
this text file is consist of three rows, first row is the set of processes,
second row is the set of resources with their number of instances and last
rows are the set of edges that shows how processes and resources relate
to each other.
For example:
P1 P2
R1 R2
P1 R1
P2 R2
R1 P2
R2 P1
In the above example, there are two processes, two resources and the
relations are:
P1 needs R1, P2 needs R2, one instance of R1 was given to P2, one instance
of R2 was given to P1.
2. Check the situation and detect if there is a deadlock
in the system or not.
3. If there is a deadlock it should print a message
with names of the processes and resources who caused the deadlock and solve
the deadlock problem by preempting one process from holding a resource,
and later give that resource back to the process that was preempted.
For the above set, your program should generate:
Number of processes = 2
Number of resources = 2
Deadlock detected at: P1->R1->P2->R2->P1
P1 Preempted
R2->P2
R1->P1
4. If there is not a deadlock it should print the message saying so.
CONDITIONS:
1- Your simulation program should work for at least
five processes and five resources.
2- Your program should not ask the user to press
any key or interact in any way.
3- You can use C++ or C or any UNIX shell script
to write the program.
4- You must be able to compile your program on a
computer with UNIX OS.
5- Use the above set to test your program. You may
change R1=1 to R1=2 to see the result, if there is no deadlock.
SUBMITTAL:
1- Hard copy of your source code and sample input
file (printed on paper).
2- Use the submit utility in my web page to submit
your source code.
3- Use at least three different conditions as your
input file.
4- Print all the results from your program on paper
and submit it.
EXTRA:
1- Make your program smart enough to avoid the deadlock
situation, so it will detect the deadlock before it occurs.
2- Make your program to accept any number of processes
and resources.