Commit | Line | Data |
---|---|---|
931b8415 | 1 | .\" Copyright (c) 1980, 1991 The Regents of the University of California. |
88b3ccf2 | 2 | .\" All rights reserved. |
b67f7691 | 3 | .\" |
91cff1e1 | 4 | .\" %sccs.include.redist.man% |
88b3ccf2 | 5 | .\" |
931b8415 | 6 | .\" @(#)getrlimit.2 6.7 (Berkeley) %G% |
b67f7691 | 7 | .\" |
931b8415 CL |
8 | .Dd |
9 | .Dt GETRLIMIT 2 | |
10 | .Os BSD 4 | |
11 | .Sh NAME | |
12 | .Nm getrlimit , | |
13 | .Nm setrlimit | |
14 | .Nd control maximum system resource consumption | |
15 | .Sh SYNOPSIS | |
16 | .Fd #include <sys/time.h> | |
17 | .Fd #include <sys/resource.h> | |
18 | .Ft int | |
19 | .Fn getrlimit "int resource" "struct rlimit *rlp" | |
20 | .Ft int | |
21 | .Fn setrlimit "int resource" "struct rlimit *rlp" | |
22 | .Sh DESCRIPTION | |
0f8ac93b KM |
23 | Limits on the consumption of system resources by the current process |
24 | and each process it creates may be obtained with the | |
931b8415 | 25 | .Fn getrlimit |
0f8ac93b | 26 | call, and set with the |
931b8415 | 27 | .Fn setrlimit |
0f8ac93b | 28 | call. |
931b8415 | 29 | .Pp |
0f8ac93b | 30 | The |
931b8415 | 31 | .Fa resource |
0f8ac93b | 32 | parameter is one of the following: |
931b8415 CL |
33 | .Bl -tag -width RLIMIT_FSIZEAA |
34 | .It Dv RLIMIT_CPU | |
7345eeba | 35 | the maximum amount of cpu time (in seconds) to be used by |
0f8ac93b | 36 | each process. |
931b8415 | 37 | .It Dv RLIMIT_FSIZE |
63b0bb9c | 38 | the largest size, in bytes, of any single file that may be created. |
931b8415 | 39 | .It Dv RLIMIT_DATA |
0f8ac93b KM |
40 | the maximum size, in bytes, of the data segment for a process; |
41 | this defines how far a program may extend its break with the | |
931b8415 | 42 | .Xr sbrk 2 |
0f8ac93b | 43 | system call. |
931b8415 | 44 | .It Dv RLIMIT_STACK |
0f8ac93b | 45 | the maximum size, in bytes, of the stack segment for a process; |
65d38ebd MK |
46 | this defines how far a program's stack segment may be extended. |
47 | Stack extension is performed automatically by the system. | |
931b8415 | 48 | .It Dv RLIMIT_CORE |
0f8ac93b | 49 | the largest size, in bytes, of a |
931b8415 | 50 | .Xr core |
63b0bb9c | 51 | file that may be created. |
931b8415 | 52 | .It Dv RLIMIT_RSS |
65d38ebd MK |
53 | the maximum size, in bytes, to which a process's resident set size may |
54 | grow. This imposes a limit on the amount of physical memory | |
0f8ac93b | 55 | to be given to a process; if memory is tight, the system will |
63b0bb9c | 56 | prefer to take memory from processes that are exceeding their |
0f8ac93b | 57 | declared resident set size. |
931b8415 CL |
58 | .El |
59 | .Pp | |
19a3a68f KB |
60 | A resource limit is specified as a soft limit and a hard limit. When a |
61 | soft limit is exceeded a process may receive a signal (for example, if | |
62 | the cpu time or file size is exceeded), but it will be allowed to | |
63 | continue execution until it reaches the hard limit (or modifies | |
0f8ac93b | 64 | its resource limit). The |
931b8415 | 65 | .Em rlimit |
0f8ac93b | 66 | structure is used to specify the hard and soft limits on a resource, |
931b8415 | 67 | .Bd -literal -offset indent |
0f8ac93b KM |
68 | struct rlimit { |
69 | int rlim_cur; /* current (soft) limit */ | |
70 | int rlim_max; /* hard limit */ | |
71 | }; | |
931b8415 CL |
72 | .Ed |
73 | .Pp | |
0f8ac93b KM |
74 | Only the super-user may raise the maximum limits. Other users |
75 | may only alter | |
931b8415 | 76 | .Fa rlim_cur |
0f8ac93b | 77 | within the range from 0 to |
931b8415 | 78 | .Fa rlim_max |
0f8ac93b | 79 | or (irreversibly) lower |
931b8415 CL |
80 | .Fa rlim_max . |
81 | .Pp | |
82 | An | |
83 | .Dq infinite | |
84 | value for a limit is defined as | |
85 | .Dv RLIM_INFINITY | |
0f8ac93b | 86 | (0x7\&f\&f\&f\&f\&f\&f\&f). |
931b8415 | 87 | .Pp |
0f8ac93b | 88 | Because this information is stored in the per-process information, |
b67f7691 KM |
89 | this system call must be executed directly by the shell if it |
90 | is to affect all future processes created by the shell; | |
931b8415 | 91 | .Ic limit |
b67f7691 | 92 | is thus a built-in command to |
931b8415 CL |
93 | .Xr csh 1 . |
94 | .Pp | |
b67f7691 | 95 | The system refuses to extend the data or stack space when the limits |
0f8ac93b | 96 | would be exceeded in the normal way: a |
931b8415 | 97 | .Xr break |
65d38ebd MK |
98 | call fails if the data space limit is reached. |
99 | When the stack limit is reached, the process receives | |
931b8415 CL |
100 | a segmentation fault |
101 | .Pq Dv SIGSEGV ; | |
102 | if this signal is not | |
65d38ebd MK |
103 | caught by a handler using the signal stack, this signal |
104 | will kill the process. | |
931b8415 | 105 | .Pp |
19a3a68f | 106 | A file I/O operation that would create a file larger that the process' |
931b8415 CL |
107 | soft limit will cause the write to fail and a signal |
108 | .Dv SIGXFSZ | |
109 | to be | |
19a3a68f | 110 | generated; this normally terminates the process, but may be caught. When |
931b8415 CL |
111 | the soft cpu time limit is exceeded, a signal |
112 | .Dv SIGXCPU | |
113 | is sent to the | |
0f8ac93b | 114 | offending process. |
931b8415 | 115 | .Sh RETURN VALUES |
0f8ac93b | 116 | A 0 return value indicates that the call succeeded, changing |
931b8415 | 117 | or returning the resource limit. A return value of -1 indicates |
0f8ac93b | 118 | that an error occurred, and an error code is stored in the global |
931b8415 CL |
119 | location |
120 | .Va errno . | |
121 | .Sh ERRORS | |
122 | .Fn Getrlimit | |
123 | and | |
124 | .Fn setrlimit | |
125 | will fail if: | |
126 | .Bl -tag -width Er | |
127 | .It Bq Er EFAULT | |
128 | The address specified for | |
129 | .Fa rlp | |
130 | is invalid. | |
131 | .It Bq Er EPERM | |
132 | The limit specified to | |
133 | .Fn setrlimit | |
134 | would have | |
0f8ac93b | 135 | raised the maximum limit value, and the caller is not the super-user. |
931b8415 CL |
136 | .El |
137 | .Sh SEE ALSO | |
138 | .Xr csh 1 , | |
139 | .Xr quota 2 , | |
140 | .Xr sigvec 2 , | |
141 | .Xr sigstack 2 | |
142 | .Sh BUGS | |
b67f7691 | 143 | There should be |
931b8415 | 144 | .Ic limit |
b67f7691 | 145 | and |
931b8415 | 146 | .Ic unlimit |
b67f7691 | 147 | commands in |
931b8415 | 148 | .Xr sh 1 |
b67f7691 | 149 | as well as in |
931b8415 CL |
150 | .Xr csh . |
151 | .Sh HISTORY | |
152 | The | |
153 | .Nm | |
154 | function call appeared in | |
155 | .Bx 4.2 . |