Resources in Operating System:
A resource is an object that is used by a process. It can be a piece of hardware
- Tape drive
- Disk drive
A resource can be a piece of information such as:
- A record within a file
- A shared variable
- A critical section
A computer typically has many different resources. In some cases, there maybe
many instances of a resource of a given type. A process needing one of these
resources can use any one of them. In other cases there may be only one instance
of a resource.
Types of Resources:
Resources come in two types: preemptible and nonpreemptible. A preemptible
resource is one that can be allocated to a given process for a period of time.
Then it can be allocated to another process. Then it can be reallocated to the
first process without any negative effects. Examples of preemptible resources
- Array processor
A nonpreemptible resource cannot be taken from one process and given to another
without side effects. One example is a printer. A printer cannot be take away
from one process and given to another process in the middle of a print job.
Deadlocks usually involve nonpreemptible resources. The usual sequence of events
that occur as a resource is used is:
1. Request the resource: One of two things can happen when a resource is
requested. The request can be granted immediately if it is available. The
request can be postponed or blocked until a later time.
2. Use the resource: Once the resource has been acquired, it can be used.
3. Release the resource: When the process no longer needs the resource, it
releases it. Usually it is released as soon as possible.