The getrlimit and setrlimit system callsallow a process to read and set limits on the
system resources that it can consume.You may be familiar with the ulimit shell command,
which enables you to restrict the resource usage of programs you run; these system calls
allow a program to do this programmatically.
For each resource there are two limits,the hard limit and the soft limit.The soft limit
may never exceed the hard limit,and only processes with superuser privilege may
change the hard limit.Typically,an application program will reduce the soft limit to
place a throttle on the resources it uses.
Both getrlimit and setrlimit take as arguments a code specifying the resource
limit type and a pointer to a structrlimit variable.The getrlimit call fills the fields
of this structure,while the setrlimit call changes the limit based on its contents.The
rlimit structure has two fields:rlim_cur is the soft limit,and rlim_max is the hard
limit.
Some of the most useful resource limits that may be changed are listed here,with
their codes:
* RLIMIT_CPU--The maximum CPU time,in seconds,used by a program.This is
the amount of time that the program is actually executing on the CPU,which is
not necessarily the same as wall-clock time.If the program exceeds this time
limit,it is terminated with a SIGXCPU signal.
* RLIMIT_DATA--The maximum amount of memory that a program can allocate
for its data.Additional allocation beyond this limit will fail.
* RLIMIT_NPROC--The maximum number of child processesthat can be running
fork and too many processes belonging to this for this user.If the process calls
user are running on the system,fork fails.
* RLIMIT_NOFILE--The maximum number of file descriptors that the process may
have open at one time.
system resources that it can consume.You may be familiar with the ulimit shell command,
which enables you to restrict the resource usage of programs you run; these system calls
allow a program to do this programmatically.
For each resource there are two limits,the hard limit and the soft limit.The soft limit
may never exceed the hard limit,and only processes with superuser privilege may
change the hard limit.Typically,an application program will reduce the soft limit to
place a throttle on the resources it uses.
Both getrlimit and setrlimit take as arguments a code specifying the resource
limit type and a pointer to a structrlimit variable.The getrlimit call fills the fields
of this structure,while the setrlimit call changes the limit based on its contents.The
rlimit structure has two fields:rlim_cur is the soft limit,and rlim_max is the hard
limit.
Some of the most useful resource limits that may be changed are listed here,with
their codes:
* RLIMIT_CPU--The maximum CPU time,in seconds,used by a program.This is
the amount of time that the program is actually executing on the CPU,which is
not necessarily the same as wall-clock time.If the program exceeds this time
limit,it is terminated with a SIGXCPU signal.
* RLIMIT_DATA--The maximum amount of memory that a program can allocate
for its data.Additional allocation beyond this limit will fail.
* RLIMIT_NPROC--The maximum number of child processesthat can be running
fork and too many processes belonging to this for this user.If the process calls
user are running on the system,fork fails.
* RLIMIT_NOFILE--The maximum number of file descriptors that the process may
have open at one time.