Commit | Line | Data |
---|---|---|
b67f7691 KM |
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 | .\" | |
7345eeba | 5 | .\" @(#)getrlimit.2 6.1 (Berkeley) %G% |
b67f7691 | 6 | .\" |
7345eeba | 7 | .TH GETRLIMIT 2 "" |
b67f7691 KM |
8 | .UC 4 |
9 | .SH NAME | |
0f8ac93b | 10 | getrlimit, setrlimit \- control maximum system resource consumption |
b67f7691 | 11 | .SH SYNOPSIS |
0f8ac93b KM |
12 | .ft B |
13 | .nf | |
14 | #include <sys/time.h> | |
15 | #include <sys/resource.h> | |
b67f7691 | 16 | .PP |
0f8ac93b KM |
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 | |
b67f7691 | 28 | .SH DESCRIPTION |
0f8ac93b KM |
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 | |
7345eeba | 41 | the maximum amount of cpu time (in seconds) to be used by |
0f8ac93b KM |
42 | each process. |
43 | .TP 17 | |
44 | RLIMIT_FSIZE | |
45 | the largest size, in bytes, of any single file which 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 | |
b67f7691 | 50 | .IR sbrk (2) |
0f8ac93b KM |
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 | either automatically by the system, or explicitly by a user with | |
57 | the | |
58 | .IR sbrk (2) | |
59 | system call. | |
60 | .TP 17 | |
61 | RLIMIT_CORE | |
62 | the largest size, in bytes, of a | |
63 | .I core | |
64 | file which may be created. | |
65 | .TP 17 | |
66 | RLIMIT_RSS | |
67 | the maximum size, in bytes, a process's resident set size may | |
68 | grow to. This imposes a limit on the amount of physical memory | |
69 | to be given to a process; if memory is tight, the system will | |
70 | prefer to take memory from processes which are exceeding their | |
71 | declared resident set size. | |
72 | .PP | |
73 | A resource limit is specified as a soft limit and a hard limit. | |
74 | When a soft limit is exceeded a process may receive a signal | |
75 | (for example, if the cpu time is exceeded), but it will be allowed | |
76 | to continue execution until it reaches the hard limit (or modifies | |
77 | its resource limit). The | |
78 | .I rlimit | |
79 | structure is used to specify the hard and soft limits on a resource, | |
80 | .PP | |
81 | .nf | |
82 | .RS | |
83 | .DT | |
84 | struct rlimit { | |
85 | int rlim_cur; /* current (soft) limit */ | |
86 | int rlim_max; /* hard limit */ | |
87 | }; | |
88 | .RE | |
89 | .fi | |
90 | .PP | |
91 | Only the super-user may raise the maximum limits. Other users | |
92 | may only alter | |
93 | .I rlim_cur | |
94 | within the range from 0 to | |
95 | .I rlim_max | |
96 | or (irreversibly) lower | |
97 | .IR rlim_max . | |
98 | .PP | |
7345eeba | 99 | An \*(lqinfinite\*(rq value for a limit is defined as RLIM_INFINITY |
0f8ac93b | 100 | (0x7\&f\&f\&f\&f\&f\&f\&f). |
b67f7691 | 101 | .PP |
0f8ac93b | 102 | Because this information is stored in the per-process information, |
b67f7691 KM |
103 | this system call must be executed directly by the shell if it |
104 | is to affect all future processes created by the shell; | |
105 | .I limit | |
106 | is thus a built-in command to | |
107 | .IR csh (1). | |
108 | .PP | |
109 | The system refuses to extend the data or stack space when the limits | |
0f8ac93b | 110 | would be exceeded in the normal way: a |
b67f7691 KM |
111 | .I break |
112 | call fails if the data space limit is reached, or the process is | |
113 | killed when the stack limit is reached (since the stack cannot be | |
114 | extended, there is no way to send a signal!). | |
115 | .PP | |
116 | A file i/o operation which would create a file which is too large | |
117 | will cause a signal SIGXFSZ to be generated, this normally terminates | |
118 | the process, but may be caught. | |
0f8ac93b KM |
119 | When the soft cpu time limit is exceeded, a signal SIGXCPU is sent to the |
120 | offending process. | |
121 | .SH "RETURN VALUE | |
122 | A 0 return value indicates that the call succeeded, changing | |
123 | or returning the resource limit. A return value of \-1 indicates | |
124 | that an error occurred, and an error code is stored in the global | |
125 | location \fIerrno\fP. | |
126 | .SH "ERRORS | |
127 | The possible errors are: | |
128 | .TP 15 | |
129 | [EFAULT] | |
130 | The address specified for \fIrlp\fP is invalid. | |
131 | .TP 15 | |
132 | [EPERM] The limit specified to \fIsetrlimit\fP would have | |
133 | raised the maximum limit value, and the caller is not the super-user. | |
b67f7691 | 134 | .SH SEE ALSO |
0f8ac93b | 135 | csh(1), quota(2) |
b67f7691 | 136 | .SH BUGS |
b67f7691 KM |
137 | There should be |
138 | .I limit | |
139 | and | |
140 | .I unlimit | |
141 | commands in | |
142 | .IR sh (1) | |
143 | as well as in | |
144 | .IR csh. |