| 1 | .\" Copyright (c) 1980 Regents of the University of California. |
| 2 | .\" All rights reserved. The Berkeley software License Agreement |
| 3 | .\" specifies the terms and conditions for redistribution. |
| 4 | .\" |
| 5 | .\" @(#)getrlimit.2 6.3 (Berkeley) %G% |
| 6 | .\" |
| 7 | .TH GETRLIMIT 2 "" |
| 8 | .UC 4 |
| 9 | .SH NAME |
| 10 | getrlimit, setrlimit \- control maximum system resource consumption |
| 11 | .SH SYNOPSIS |
| 12 | .ft B |
| 13 | .nf |
| 14 | #include <sys/time.h> |
| 15 | #include <sys/resource.h> |
| 16 | .PP |
| 17 | .ft B |
| 18 | getrlimit(resource, rlp) |
| 19 | int resource; |
| 20 | struct rlimit *rlp; |
| 21 | .PP |
| 22 | .ft B |
| 23 | setrlimit(resource, rlp) |
| 24 | int resource; |
| 25 | struct rlimit *rlp; |
| 26 | .fi |
| 27 | .ft R |
| 28 | .SH DESCRIPTION |
| 29 | Limits on the consumption of system resources by the current process |
| 30 | and each process it creates may be obtained with the |
| 31 | .I getrlimit |
| 32 | call, and set with the |
| 33 | .I setrlimit |
| 34 | call. |
| 35 | .PP |
| 36 | The |
| 37 | .I resource |
| 38 | parameter is one of the following: |
| 39 | .TP 17 |
| 40 | RLIMIT_CPU |
| 41 | the maximum amount of cpu time (in seconds) to be used by |
| 42 | each process. |
| 43 | .TP 17 |
| 44 | RLIMIT_FSIZE |
| 45 | the largest size, in bytes, of any single file that may be created. |
| 46 | .TP 17 |
| 47 | RLIMIT_DATA |
| 48 | the maximum size, in bytes, of the data segment for a process; |
| 49 | this defines how far a program may extend its break with the |
| 50 | .IR sbrk (2) |
| 51 | system call. |
| 52 | .TP 17 |
| 53 | RLIMIT_STACK |
| 54 | the maximum size, in bytes, of the stack segment for a process; |
| 55 | this defines how far a program's stack segment may be extended. |
| 56 | Stack extension is performed automatically by the system. |
| 57 | .TP 17 |
| 58 | RLIMIT_CORE |
| 59 | the largest size, in bytes, of a |
| 60 | .I core |
| 61 | file that may be created. |
| 62 | .TP 17 |
| 63 | RLIMIT_RSS |
| 64 | the maximum size, in bytes, to which a process's resident set size may |
| 65 | grow. This imposes a limit on the amount of physical memory |
| 66 | to be given to a process; if memory is tight, the system will |
| 67 | prefer to take memory from processes that are exceeding their |
| 68 | declared resident set size. |
| 69 | .PP |
| 70 | A resource limit is specified as a soft limit and a hard limit. |
| 71 | When a soft limit is exceeded a process may receive a signal |
| 72 | (for example, if the cpu time is exceeded), but it will be allowed |
| 73 | to continue execution until it reaches the hard limit (or modifies |
| 74 | its resource limit). The |
| 75 | .I rlimit |
| 76 | structure is used to specify the hard and soft limits on a resource, |
| 77 | .PP |
| 78 | .nf |
| 79 | .RS |
| 80 | .DT |
| 81 | struct rlimit { |
| 82 | int rlim_cur; /* current (soft) limit */ |
| 83 | int rlim_max; /* hard limit */ |
| 84 | }; |
| 85 | .RE |
| 86 | .fi |
| 87 | .PP |
| 88 | Only the super-user may raise the maximum limits. Other users |
| 89 | may only alter |
| 90 | .I rlim_cur |
| 91 | within the range from 0 to |
| 92 | .I rlim_max |
| 93 | or (irreversibly) lower |
| 94 | .IR rlim_max . |
| 95 | .PP |
| 96 | An \*(lqinfinite\*(rq value for a limit is defined as RLIM_INFINITY |
| 97 | (0x7\&f\&f\&f\&f\&f\&f\&f). |
| 98 | .PP |
| 99 | Because this information is stored in the per-process information, |
| 100 | this system call must be executed directly by the shell if it |
| 101 | is to affect all future processes created by the shell; |
| 102 | .I limit |
| 103 | is thus a built-in command to |
| 104 | .IR csh (1). |
| 105 | .PP |
| 106 | The system refuses to extend the data or stack space when the limits |
| 107 | would be exceeded in the normal way: a |
| 108 | .I break |
| 109 | call fails if the data space limit is reached. |
| 110 | When the stack limit is reached, the process receives |
| 111 | a segmentation fault (SIGSEGV); if this signal is not |
| 112 | caught by a handler using the signal stack, this signal |
| 113 | will kill the process. |
| 114 | .PP |
| 115 | A file I/O operation that would create a file that is too large |
| 116 | will cause a signal SIGXFSZ to be generated; this normally terminates |
| 117 | the process, but may be caught. |
| 118 | When the soft cpu time limit is exceeded, a signal SIGXCPU is sent to the |
| 119 | offending process. |
| 120 | .SH "RETURN VALUE |
| 121 | A 0 return value indicates that the call succeeded, changing |
| 122 | or returning the resource limit. A return value of \-1 indicates |
| 123 | that an error occurred, and an error code is stored in the global |
| 124 | location \fIerrno\fP. |
| 125 | .SH "ERRORS |
| 126 | The possible errors are: |
| 127 | .TP 15 |
| 128 | [EFAULT] |
| 129 | The address specified for \fIrlp\fP is invalid. |
| 130 | .TP 15 |
| 131 | [EPERM] The limit specified to \fIsetrlimit\fP would have |
| 132 | raised the maximum limit value, and the caller is not the super-user. |
| 133 | .SH SEE ALSO |
| 134 | csh(1), quota(2), sigvec(2), sigstack(2) |
| 135 | .SH BUGS |
| 136 | There should be |
| 137 | .I limit |
| 138 | and |
| 139 | .I unlimit |
| 140 | commands in |
| 141 | .IR sh (1) |
| 142 | as well as in |
| 143 | .IR csh. |