setrlimit()--Set resource limit


  Syntax
 #include <sys/resource.h>

 int setrlimit(int resource, const struct rlimit *rlp); 
  Service Program Name: QP0WSRV1

  Default Public Authority: *USE

  Threadsafe: Yes

The setrlimit() function sets the resource limit for the specified resource. A resource limit is a way for the operating system to enforce a limit on a variety of resources used by a process. A resource limit is represented by a rlimit structure. The rlim_cur member specifies the current or soft limit and the rlim_max member specifies the maximum or hard limit.

A soft limit can be changed to any value that is less than or equal to the hard limit. The hard limit can be changed to any value that is greater than or equal to the soft limit. Only a process with appropriate authorities can increase a hard limit.

The setrlimit() function supports the following resources:

RLIMIT_FSIZE (0) The maximum size of a file in bytes that can be created by a process.

The setrlimit() function does not support setting the following resources: RLIMIT_AS, RLIMIT_CORE, RLIMIT_CPU, RLIMIT_DATA, RLIMIT_NOFILE, and RLIMIT_STACK. The setrlimit() function returns -1 and sets errno to ENOTSUP when called with one of these resources.

The value of RLIM_INFINITY is considered to be larger than any other limit value. If the value of the limit is set to RLIM_INFINITY, then a limit is not enforced for that resource. If the value of the limit is set to RLIM_SAVED_MAX, the new limit is the corresponding saved hard limit. If the value of the limit is RLIM_SAVED_CUR, the new limit is the corresponding saved soft limit.

Parameters

resource
(Input)

The resource to set the limits for.

*rlp
(Input)

Pointer to a struct rlim_t that contains the new values for the hard and soft limits.


Authorities and Locks

The current user profile must have *JOBCTL special authority to increase the hard limit.


Return Value

0 setrlimit() was successful.
-1 setrlimit() was not successful. The errno variable is set to indicate the error.


Error Conditions

If setrlimit() is not successful, errno usually indicates one of the following errors. Under some conditions, errno could indicate an error other than those listed here.

[EFAULT]

The address used for an argument is not correct.

In attempting to use an argument in a call, the system detected an address that is not valid.

While attempting to access a parameter passed to this function, the system detected an address that is not valid.

[EINVAL]

An invalid parameter was found.

An invalid resource was specified.

The new soft limit is greater the new hard limit.

The new hard limit is lower than the new soft limit.

[EPERM]

Permission denied.

An attempt was made to increase the hard limit and the current user profile does not have *JOBCTL special authority.

[ENOTSUP]

Operation not supported.

The operation, though supported in general, is not supported for the requested resource.


Related Information


Example

See Code disclaimer information for information pertaining to code examples.

#include <sys/resource.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>

int main (int argc, char *argv[])
{
  struct rlimit limit;
  
  /* Set the file size resource limit. */
  limit.rlim_cur = 65535;
  limit.rlim_max = 65535;
  if (setrlimit(RLIMIT_FSIZE, &limit) != 0) {
    printf("setrlimit() failed with errno=%d\n", errno);
    exit(1);
  }

  /* Get the file size resource limit. */
  if (getrlimit(RLIMIT_FSIZE, &limit) != 0) {
    printf("getrlimit() failed with errno=%d\n", errno);
    exit(1);
  }

  printf("The soft limit is %llu\n", limit.rlim_cur);
  printf("The hard limit is %llu\n", limit.rlim_max);
  exit(0);
}
Example Output:
The soft limit is 65535
The hard limit is 65535



Introduced: V5R2
Top | UNIX-Type APIs | APIs by category