Search code examples
algorithmoperating-systembankers-algorithm

Bankers Algorithm processes


Using Bankers algorithm,

If a process (p1) is unable to complete by any other process p2,p3,p4 etc giving up it's resources singly, can they ALL relinquish their resources together so p1 could complete?

Or is that not a thing that could be done?


Solution

  • Are you asking about capabilities of abstract processes, or of the Banker's algorithm in particular?

    If it's abstract processes, then yes, it's easily possible. Create a signal yield_all, and code each process to relinquish the resources when it receives that signal. Some master process will have to send the signal to each of P2, P3, and P4, and then allow P1 to proceed with its allocation. Implementation details are up to the designer.


    If you're asking about the Banker's algorithm, I'm not entirely clear what you need. No allocation is allowed to proceed unless the system is still in a safe state: each process is capable of terminating (thus returning all resources) in some order, with the remaining system availability.

    Thus, in the situation you describe, forcing any other process to yield resources is not a valid operation. Rather, P1 has to wait until the others have terminated normally, before it is allowed to allocate the requested resources. If this is not possible, then the system is in an unsafe state -- one or more prior requests should not have been granted.

    Does that answer your question?