The $ru_who argument is either RUSAGE_SELF (the current process) or
RUSAGE_CHILDREN (all the child processes of the current process)
or it maybe left away in which case RUSAGE_SELF is used.
The RUSAGE_CHILDREN is the total sum of all the so far
terminated (either successfully or unsuccessfully) child processes:
there is no way to find out information about child processes still
running.
On some systems (those supporting both
getrusage()
and the POSIX
threads) there is also RUSAGE_THREAD. The BSD::Resource supports the
RUSAGE_THREAD if it is present but understands nothing more about the
POSIX threads themselves.
In list context getrusage() returns the current resource usages as a list. On failure it returns an empty list.
The elements of the list are, in order:
In scalar context getrusage() returns the current resource usages as a an object. The object can be queried via methods named exactly like the middle column, name, in the above table.
For a detailed description about the values returned by
getrusage()
please consult your usual C programming documentation about
getrusage()
and also the header file <sys/resource.h>.
(In Solaris, this might be <sys/rusage.h>).
Note 1: officially HP-UX does not support getrusage() at all but for the time being, it does seem to.
Note 2: Because not all kernels are BSD and also because of the sloppy
support of
getrusage()
by many vendors many of the values may not be
updated. For example Solaris 1 claims in <sys/rusage.h>
that the ixrss and the isrss fields are always zero.
The $resource argument can be one of
What limits are available depends on the operating system. See below
for
get_rlimits()
on how to find out which limits are available.
The last two pairs (NO_FILE, OPEN_MAX) and (AS, VMEM)
are the same, the former being the BSD names and the latter SVR4 names.
Two meta-resource-symbols might exist
RLIM_NLIMITS being the number of possible (but not necessarily fully
supported) resource limits, see also the
get_rlimits()
call below.
RLIM_INFINITY is useful in
setrlimit()
, the RLIM_INFINITY is
represented as -1.
In list context getrlimit() returns the current soft and hard resource limits as a list. On failure it returns an empty list.
Processes have soft and hard resource limits. On crossing the soft
limit they receive a signal (for example the XCPU or XFSZ,
corresponding to the RLIMIT_CPU and RLIMIT_FSIZE, respectively).
The processes can trap and handle some of these signals, please see
Signals. After the hard limit the processes will be
ruthlessly killed by the KILL signal which cannot be caught.
NOTE: the level of 'support' for a resource varies. Not all the systems
Again, please consult your usual C programming documentation.
One notable exception for the better: officially HP-UX does not support getrlimit() at all but for the time being, it does seem to.
In scalar context
getrlimit()
returns the current soft and hard
resource limits as an object. The object can be queried via methods
cur and max, the current and maximum resource limits for the
$resource, respectively.
getpriority()
returns the current priority. NOTE:
getpriority()
can return zero or negative values completely legally. On failure
getpriority()
returns undef (and $! is set as usual).
The priorities returned by
getpriority()
are in the (inclusive) range
PRIO_MIN...PRIO_MAX. The $pr_which argument can be any of
PRIO_PROCESS (a process) PRIO_USER (a user), or PRIO_PGRP (a
process group). The $pr_who argument tells which process/user/process
group, 0 signifying the current one.
Usual values for PRIO_MIN, PRIO_MAX, are -20, 20. A negative
value means better priority (more impolite process), a positive value
means worse priority (more polite process).
NOTE: in AIX if the BSD compatibility library is not installed or
not found by the installation procedure of the BSD::Resource the
PRIO_MIN is 0 (corresponding to -20) and PRIO_MAX is 39 (corresponding
to 19, the BSD priority 20 is unreachable).
setrlimit()
returns true on success and undef on failure.
NOTE: A normal user process can only lower its resource limits.
Soft or hard limit RLIM_INFINITY means as much as possible, the
real hard limits are normally buried inside the kernel and are very
system-dependent.
setpriority()
is used to change the scheduling priority. A positive
priority means a more polite process/process group/user; a negative
priority means a more impoite process/process group/user.
The priorities handled by
setpriority()
are [PRIO_MIN,PRIO_MAX].
A normal user process can only lower its priority (make it more positive).
NOTE: A successful call returns 1, a failed one 0.
NOTE: This is not a real BSD function. It is a convenience function.
get_rlimits() returns a reference to hash which has the names of the available resource limits as keys and their indices (those which are needed as the first argument to getrlimit() and setrlimit() ) as values. For example:
jhi@iki.fi