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.
resource.RLIMIT_INFINITY:
This is the limit for an unlimited resource.
resource.RLIMIT_CORE:
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.
resource.RLIMIT_CPU:
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.
resource.RLIMIT_FSIZE:
This returns the maximum size of the file that the process is allowed to create.
resource.RLIMIT_DATA:
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.
resource.RLIMIT_STACK:
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.
resource.RIMIT_RSS:
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.
resource.RLIMIT_NPROC:
This gives the maximum number of processes the current process may create.
resource.RLIMIT_NOFILE:
This gives the maximum number of open file descriptors allowed for the current process.
resource.RLIMIT_OFILE:
This is the BSD name of RLIMIT_NOFILE.
resource.RLIMIT_MEMLOCK:
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.
Comments