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.
This method is used to return the soft and hard limits as a tuple. If the specified resource is invalid, it will raise ValueError.
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