A resource can be either a printer, hard drive, scanner or keyboard. The operating system (OS) allocates resources to the computer processes.
A process is any program in execution. The program needs resources to complete the task. Suppose the MS Word program is running and it needs a printer to print the document. If the printer is free then OS assigns that printer resource to the MS Word program. If the printer is already assigned to another process or program then the MS Word program or process has to wait.
Types of resource allocation
Two types of resource allocation occur in the operating system
Resource allocation with deadlock
Suppose there are two processes P1 and P2. And two resources R1 and R2.
P1 is holding R2 and P1 is requesting R1
P2 is holding R1 and P2 is requesting R2
As shown in the diagram it is making a circle and if a circle is made between processes and resources then there are chances that deadlock will occur.
Resource allocation without deadlock
If there are multiple instances of the resource, there are chances that deadlock will not occur. Also if the circle is not made between processes and resources then deadlock will not occur.
Example of resource allocation
An example of resource allocation is MS word which is a process and it is requesting a printer that is a resource. If a printer is held by another process then MS Word has to wait.