What you will learn:
A way to prevent at *runtime* a possibility of a deadlock occurring in a system
Assignment
Write a program with following specifications:
Command line input: name of a file
- The file contains the initial state of the system as given below (example
included in right column)
#no of resources
4
#no of instances of each resource
2 4 5 3
#no of processes
3
#no of instances of each resource that
1 1 1 1, 2 3 1 2, 2 2 1 3
each processes needs in its lifetime.
The rule is that once a process uses a resource instance and returns it,
the process no more needs it. For example, in above set of 3 processes,
If P2 finishes with 1 instance of resource r3, it will only need
3-1=2 instances of r3 in future.
A process completes immediately when its need eventually reduces to 0.
Read this in
The programs then waits to accept a resource allocation or release requests-
this is supplied through keyboard
For example: 0 a 1 0 1 1 indicates
that p0 has requested allocation of 1 instance of R0, R2 and R3 each.
or
3 r 0 0 0 3 indicates that p3 is releasing
3 instances of resource r3
Your program should declare the result: (1) should this request
be granted? (i.e. guaranteeing that there will be no deadlock
in future considering a worst remaining demand for resources)
(2) if your answer is yes, print the safe sequence in which all remaining
needs can be granted one by one
and also grant the request, making necessary changes to system's
state.
If the requesting process's need is NIL, the program internally releases
all its resources.
Go back to accept another request till all processes finish with
all there needs
Some sample initial state input files and request patterns can
be found here
Download them and see using your editor.
What to submit
your single C program + readme for identifying
any special contributions
Donot submit your binaries, executables. Your marks will be reduced if you do so.
Some Pointers
You can use fopen, fopen, fclose, fscanf etc for file i/o.
Submission
Assignment no=9.
Submit your file using ~oslab/submit script as in: ~oslab/submit 9
xyz.c
submit script accepts assignment no. in its first argument. Any number
of files may be submitted through subsequent arguments.
You may submit any number of times before 6:00pm. Old files are overwritten
in resubmission.
Deadline: 5:00pm
Enjoy.