Resource Usage information using python














































Resource Usage information using python



Resource Usage Information using Python:

when we need to measure the UNIX resource usage, we use the resource module on our programs. This module also can control the resource utilization.
We import this module by using the following syntax

import resource

Resource Limits:

we can use the setrlimit() to limit the resource utilization. There are 2 parameters to limit the resources. These parameters are soft limit and the hard limit. The soft limit is basically the current limit, it can be changed over process, but it cannot exceed the hard limit. The hard limit can be reduced to any value above the soft limit, but cannot increase it.

There are some methods and constants related to resource limiting. These are.

 resource.getrlimit(resource):

This method is used to return the soft and hard limits as a tuple. If the specified resource is invalid, it will raise ValueError.

 resource.setrlimit(resource, limits):

This method is used to set limits to the resources. The limits can be assigned as a tuple of soft and hard limits. We can also use RLIM_INFINITY to make unlimited resource.

 resource.prlimit(pid, resource[, limits]):

This method is a combination of setrlimit() and getrlimit() methods. It can get and set the resource limits at the same time for an arbitrary process. When the pid is 0, then it works on the current process.

next, we will see resource limits constant









Comments