Computers have evolved over time in a better way and in today's world, almost all the tasks are performed efficiently using computers. For performing these tasks, computers make use of the resources available to it. We always try to keep the utilization of the computer resources in the best possible way, which also aids in increasing the throughput and response times of the computer.
This module in python provides basic mechanisms for measuring and controlling system resources utilized by a program.
Symbolic constants are used to specify particular system resources and to request usage information about either the current process or its children. If there is a syscall failure, the OSError is raised.
Let's first talk about some such symbols related to the resource limits in this module.
These symbols basically define resources whose consumption can be controlled using the setrlimit() and getrlimit() functions described in the later article(Python resource library limit symbolic constants continued). The values of these symbols are exactly the constants used by C programs.
The following symbols are useful in using the resource library resource limit functions.
This is the limit for an unlimited resource.
This attribute returns 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.
The core file of a process contains the detailed copy of the state of the process at the instant of its failure, including the process registers and memory(which includes shared memory depending upon configuration details). With the help of this picture we can extrapolate backward in time to find the initial mistake that led to the failure. With the properly collected core files and associated information, we can solve, or otherwise extract the information about the failing process.
This is the maximum amount of processor time in seconds that the process can use. If the time limit exceeds, then a SIGXCPU signal is sent to the process which results in the default action of abnormal termination of the process.
This returns the maximum size of the file that the process is allowed to create.
This gives the maximum size in bytes of the process's heap. Heap memory (also called the dynamic memory) is essentially a large pool of memory (typically per process) from which the running program can request chunks.
This gives the maximum size in bytes of the call stack for the current process. This only affects the stack of the main thread in the multithreaded process.
The call stack is the mechanism for an interpreter to keep track of its place in the script that calls multiple functions like what function is currently running and what functions are called from within the function etc.
This gives the maximum resident set size that should be made available to the process.
The Resident Set Size (RSS) is the portion of the memory occupied by the process that is held in the main memory(RAM). The rest of the occupied memory exists in the swap space of file system, either because some parts of the occupied memory were paged out, or because some parts of the executable were never loaded.
This gives the maximum number of processes the current process may create.
This gives the maximum number of open file descriptors allowed for the current process.
This is the BSD name of RLIMIT_NOFILE.
This gives maximum address space which may be locked in the memory.
There are some more resource limit symbols used which are discussed in the next article.