Resource Allocation


When each process request for the resources available in the system, the operating system allocates the needed resources for its execution purpose. The resources allocated can be either a hard drive, scanner, any files in memory, or even a printer. Any program that enters into a ready or execution state is termed a process. This program requires resources from one or other processes to complete its assigned task.

In a multiprogramming environment, a process may request multiple resources at the same time, so those processes have to be waiting until it receives all the resources. A resource allocator present in the operating system is generally responsible for allocating the resources as per user request and deallocating them on completion between various processes. Resource allocation has to be assigned in such a way that all processes have enough resources required for working on their task.

Resource allocation

When resources are allocated, to the process based on the request various issues arise in multiuser processing which would be expensive to provide resources that are non-sharable to equalize with higher demands. The operating system has to allocate the resources without losing the integrity of the system.

Consider a practical example of a user working on an Excel file who wants to print some data using a printer device connected to the system. Then operating system allocates the printer based on its availability to the Excel process. The process enters into a wait state if the printer is used by another process in the system.

Allocation mechanisms used by the operating system to allocate the resources to the process are given below −

Memory allocation  When a program request for resources from the operating system, the process and the input data needs to be stored in primary memory to perform its execution. Memory manager has the responsibility to allocate resources according to the available or free spaces available and after providing memory to the requested process, execution of the program begins. Memory management has two different approaches to allocating the process into the system. In a contiguous approach where the processes are assigned to fixed blocks of memory, with larger sizes and stored in a memory location that has consecutive addresses whereas, in a non-contiguous approach, the processes are stored in different blocks that are located at different memory portions not needed to be in a consecutive manner which seems to be an efficient technique as it uses memory spaces only when needed.

Processors

The operating system has a process descriptor that specifies the process to get resources from the processors. One central processor is usually present whereas, in a multiprocessor environment, there can be many processors running at the same time serving the user request. The process control block contains information about the status of resources when each process is created. This provides states of each process such as new, running, waiting, ready, blocked, or terminated.

File permissions

Files consist of a collection of user information sometimes called programs. Resources are allocated to the file along with the access permissions specified by the owner to individual or group of users. Operations such as read, write, and execute are also allocated along with the file stored in the memory. If multiple files are requested at the same time, then some process gets into a queue until reaching its expiration.

Backup of memory

Resources can be allotted by the memory manager as said earlier. Virtual memory can also be used for storing recently used files. In the backing store, the request from the user cannot be queued, as free spaces will be assigned for the requesting process.

Allocation methods

Allocation methods When resources are allocated to the process, the operating system has two policies for allocation methods −

With Deadlock − Deadlock occurs when a process is waiting for the set of resources that is held by other processes and it waits to receive all the resources requested before it becomes unblocked. Deadlock may occur in certain conditions like Hold and Wait, Mutual exclusion, no preemption, and circular wait.

Consider an example when two processes P1 and P2 and need resources X and Y. In this case, P1 waits for resource Y where P2 holds resource Y, and P2, in turn, waits for resource X which has to be released by P1 holding it. So, the loop is created here when P1 needs resource Y and waits for P2 to release it, and P2 needs X and waits for P2 to release it. Deadlocks can be resolved by methods like detection, prevention, avoidance, and ostrich problem.

Without Deadlock − If resources available in memory are abundant and serve multiple processes simultaneously then deadlock may not occur.

Conclusion

The allocation of resources is managed and controlled by the operating systems based on the allocation mechanism. It detects the methods of allocating different resource types to memory, processor, peripherals, and backing store. Resource allocated to each process may or may not enter into a deadlock state and detection, and prevention mechanisms have to be implemented to recover from the deadlock that occurred.

Updated on: 17-Jul-2023

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements