Go to the previous, next section.

getrlimit, getrusage and setrlimit

SYNOPSIS

int getrlimit (int resource, struct rlimit *rlim);

int getrusage (int who, struct rusage *usage);

int setrlimit (int resource, const struct rlimit *rlim);

PARAMETERS

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.

DESCRIPTION

getrlimit gets the resources limits and setrlimit sets them. The resource variable is one of:

RLIMIT_CPU
CPU time in miliseconds.

RLIMIT_FSIZE
The maximum file size (in bytes).

RLIMIT_DATA
The maximum data size (in bytes).

RLIMIT_STACK
The maximum stack size (in bytes).

RLIMIT_CORE
The maximum core file size (in bytes).

RLIMIT_RSS
The maximum resident set size (in bytes).

Privision is made for a future implementation of the additionnal following values of resource:

RLIMIT_MEMLOCK
The maximum size of wired memory space.

RLIMIT_NPROC
The maximum number of processes.

RLIMIT_OFILE
The maximum number of opened files.

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 " */
};

RETURN VALUE

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.