resource --- 資源使用資訊¶
This module provides basic mechanisms for measuring and controlling system resources utilized by a program.
可用性: Unix, not WASI.
Symbolic constants are used to specify particular system resources and to request usage information about either the current process or its children.
An OSError is raised on syscall failure.
Resource Limits¶
Resources usage can be limited using the setrlimit() function described
below. Each resource is controlled by a pair of limits: a soft limit and a hard
limit. The soft limit is the current limit, and may be lowered or raised by a
process over time. The soft limit can never exceed the hard limit. The hard
limit can be lowered to any value greater than the soft limit, but not raised.
(Only processes with the effective UID of the super-user can raise a hard
limit.)
The specific resources that can be limited are system dependent. They are described in the getrlimit(2) man page. The resources listed below are supported when the underlying operating system supports them; resources which cannot be checked or controlled by the operating system are not defined in this module for those platforms.
- resource.RLIM_INFINITY¶
Constant used to represent the limit for an unlimited resource.
- resource.getrlimit(resource)¶
Returns a tuple
(soft, hard)with the current soft and hard limits of resource. RaisesValueErrorif an invalid resource is specified, orerrorif the underlying system call fails unexpectedly.
- resource.setrlimit(resource, limits)¶
Sets new limits of consumption of resource. The limits argument must be a tuple
(soft, hard)of two integers describing the new limits. A value ofRLIM_INFINITYcan be used to request a limit that is unlimited.Raises
ValueErrorif an invalid resource is specified, if the new soft limit exceeds the hard limit, or if a process tries to raise its hard limit. Specifying a limit ofRLIM_INFINITYwhen the hard or system limit for that resource is not unlimited will result in aValueError. A process with the effective UID of super-user can request any valid limit value, including unlimited, butValueErrorwill still be raised if the requested limit exceeds the system imposed limit.setrlimitmay also raiseerrorif the underlying system call fails.VxWorks only supports setting
RLIMIT_NOFILE.引發一個附帶引數
resource、limits的稽核事件resource.setrlimit。
- resource.prlimit(pid, resource[, limits])¶
Combines
setrlimit()andgetrlimit()in one function and supports to get and set the resources limits of an arbitrary process. If pid is 0, then the call applies to the current process. resource and limits have the same meaning as insetrlimit(), except that limits is optional.When limits is not given the function returns the resource limit of the process pid. When limits is given the resource limit of the process is set and the former resource limit is returned.
Raises
ProcessLookupErrorwhen pid can't be found andPermissionErrorwhen the user doesn't haveCAP_SYS_RESOURCEfor the process.引發一個附帶引數
pid、resource、limits的稽核事件resource.prlimit。可用性: Linux >= 2.6.36 with glibc >= 2.13.
在 3.4 版被加入.
These symbols define resources whose consumption can be controlled using the
setrlimit() and getrlimit() functions described below. The values of
these symbols are exactly the constants used by C programs.
The Unix man page for getrlimit(2) lists the available resources. Note that not all systems use the same symbol or same value to denote the same resource. This module does not attempt to mask platform differences --- symbols not defined for a platform will not be available from this module on that platform.
- resource.RLIMIT_CORE¶
The maximum size (in bytes) of a core file that the current process can create. This may result in the creation of a partial core file if a larger core would be required to contain the entire process image.
- resource.RLIMIT_CPU¶
The maximum amount of processor time (in seconds) that a process can use. If this limit is exceeded, a