ulimit()--Get and set process limits


  Syntax
 #include <ulimit.h>

 long int ulimit(int cmd, ...); 
  Service Program Name: QP0WSRV1

  Default Public Authority: *USE

  Threadsafe: Yes

The ulimit() function provides a way to get and set process resource limits. 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 has a current or soft limit and a maximum or hard limit.

The ulimit() function is provided for compatibility with older applications. The getrlimit() and setrlimit() functions should be used for working with resource limits.

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 ulimit() function supports the following cmd values:



Parameters

cmd
(Input)

The command to be performed.

...
(Input)

When the cmd is UL_SETFSIZE, a long int that represents the limit in 512-byte blocks.


Authorities and Locks

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


Return Value



Error Conditions

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

[EINVAL]

An invalid parameter was found.

An invalid cmd was specified.

[EPERM]

Permission denied.

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



Related Information


Example

Note: By using the code examples, you agree to the terms of the Code license and disclaimer information.

#include <ulimit.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>

int main (int argc, char *argv[])
{
  long int value;
  long int limit;
  
  /* Set the file size resource limit. */
  limit = 65535;
  errno = 0;
  value = ulimit(UL_SETFSIZE, limit);
  if ((value == -1) && (errno != 0)) {
    printf("ulimit() failed with errno=%d\n", errno);
    exit(1);
  }
  printf("The limit is set to %ld\n", value);

  /* Get the file size resource limit. */
  value = ulimit(UL_GETFSIZE);
  if ((value == -1) && (errno != 0)) {
    printf("ulimit() failed with errno=%d\n", errno);
    exit(1);
  }
  printf("The limit is %ld\n", value);

  exit(0);
}
Example Output:
The limit is set to 65535
The limit is 65535



Introduced: V5R2

[ Back to top | UNIX-Type APIs | APIs by category ]