#include <ulimit.h> long int ulimit(int cmd, ...);Service Program Name: QP0WSRV1
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:
UL_GETFSIZE (0) | Return the current or soft limit for the file size resource limit. The returned limit is in 512-byte blocks. The return value is the integer part of the file size resource limit divided by 512. |
UL_SETFSIZE (1) | Set the current or soft limit and the maximum or hard limit for the file size resource limit. The second argument is taken as a long int that represents the limit in 512-byte blocks. The specified value is multiplied by 512 to set the resource limit. If the result overflows an rlim_t, ulimit() returns -1 and sets errno to EINVAL. The new file size resource limit is returned. |
The command to be performed.
When the cmd is UL_SETFSIZE, a long int that represents the limit in 512-byte blocks.
The current user profile must have *JOBCTL special authority to increase the hard limit.
value | ulimit() was successful. The value is the requested limit. |
-1 | ulimit() was not successful. The errno variable is set to indicate the error. |
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.
An invalid parameter was found.
An invalid cmd was specified.
Permission denied.
An attempt was made to increase the hard limit and the current user profile does not have *JOBCTL special authority.
See Code disclaimer information for information pertaining to code examples.
#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
Top | UNIX-Type APIs | APIs by category |