Go to the previous, next section.
int getrlimit (int resource, struct rlimit *rlim);
int getrusage (int who, struct rusage *usage);
int setrlimit (int resource, const struct rlimit *rlim);
resource: [in] which resource to access.
rlim: (For getrlimit
) [in] points to a buffer where to put
the limit. (For setrlimit
) [out] points to a buffer where the new
limits are.
who: [in] specifies from what process(es) we want to get the ressource usage.
usage: [out] points to a buffer where the ressource usage is saved.
getrlimit
gets the resources limits and setrlimit
sets
them. The resource variable is one of:
RLIMIT_CPU
RLIMIT_FSIZE
RLIMIT_DATA
RLIMIT_STACK
RLIMIT_CORE
RLIMIT_RSS
Privision is made for a future implementation of the additionnal following values of resource:
RLIMIT_MEMLOCK
RLIMIT_NPROC
RLIMIT_OFILE
The rlimit
structure has the following format:
struct rlimit { int rlim_cur; /* current limit */ int rlim_max; /* maximum limit */ };
By setting the limit to RLIM_INFINITY
a limit can be set to
infinity.
getrusage
gets the ressource usage of the current task (for
who set to RUSAGE_SELF
) or of the child of the current task
(for who set to RUSAGE_CHILDREN
). The rusage structure has
the following definition:
struct rusage { struct timeval ru_utime; /* user time used */ struct timeval ru_stime; /* system time used */ long ru_maxrss; /* maximum resident set size */ long ru_ixrss; /* integral shared memory size */ long ru_idrss; /* integral unshared data size */ long ru_isrss; /* integral unshared stack size */ long ru_minflt; /* page reclaims */ long ru_majflt; /* page faults */ long ru_nswap; /* swaps */ long ru_inblock; /* block input operations */ long ru_oublock; /* block output operations */ long ru_msgsnd; /* messages sent */ long ru_msgrcv; /* messages received */ long ru_nsignals; /* signals received */ long ru_nvcsw; /* voluntary context switches */ long ru_nivcsw; /* involuntary " */ };
On success zero is returned. On error -1 is returned and errno
is
set to one of the following values:
For setrlimit
: EPERM
if the task does not have superuser
privileges.
For setrlimit
and getrlimit
: EINVAL
if the
ressource value is invalid.
For getrusage
: EINVAL
if the who value is invalid.
Go to the previous, next section.