
Introduction
As system resources are limited, each process is constrained by limitations imposed by the operating system. The “ulimit” command (a built-in command included in the Bourne shell [/bin/sh]) on the command line allows the user to view and adjust current system restrictions available to the shell and the processes it starts.
The C shell (/bin/csh) has a built-in command named limit that is similar.
The command “ulimit -Ha” displays the system's hard limits. Only the superuser can raise the rigid restrictions.
Each resource has a soft and hard limit associated with it.
- Soft limit: The kernel's actual limit for the related resource is the soft limit.
- Hard limit: The soft limit has a hard limit that acts as a ceiling.
Range of Soft limit: Between 0 and the hard limit.
The following structure defines the two limits:
struct rlimit {
rlim_t rlim_cur; /* Soft limit */
rlim_t rlim_max; /* Hard limit */
};
The signatures of system calls are as follows:
int getrlimit(int resource, struct rlimit *rlim);
int setrlimit(int resource, const struct rlimit *rlim);
Also see: Multiprogramming vs Multitasking, Open Source Operating System.
getrlimit()
The getrlimit() function returns the calling process's resource limits. A resource limit comprises two values: one that specifies the current (soft) limit and the other that specifies the maximum (hard) limit.
The RLIM_INFINITY value defined in sys/resource.h is more significant than any other limit value. If getrlimit() returns RLIM_INFINITY for a resource, it signifies that the implementation does not impose restrictions on it.
The resource argument indicates the resource for which hard and soft limits should be obtained. and maybe one of the following values:
- RLIMIT_CORE
The maximum size of a memory dump allowed for the process (in bytes).
- RLIMIT_CPU
The maximum amount of CPU time (in seconds) that the process is permitted.
- RLIMIT_DATA
In bytes, the maximum size of the break value for the process. This resource has a complex and soft limit value of RLIM_INFINITY in this implementation.
- RLIMIT_FSIZE
The maximum file size (in bytes) that the process can handle.
- RLIMIT_MEMLIMIT
The maximum number of usable storage above the 2-gigabyte bar can be allocated (in 1-megabyte chunks).
- RLIMIT_NOFILE
The most significant number of open file descriptors that the process is authorized to have.
- RLIMIT_STACK
The largest size of a process's stack in bytes.
- RLIMIT_AS
The process's maximum address space size, in bytes.
The rlimit structure is referenced by the rlp parameter. The members of this structure are as follows:
rlim_cur: The current (soft) limit
rlim_max: The maximum (hard) limit