1 .\" Copyright (c) 1983, 1993
2 .\" The Regents of the University of California. All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\" notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\" notice, this list of conditions and the following disclaimer in the
11 .\" documentation and/or other materials provided with the distribution.
12 .\" 3. All advertising materials mentioning features or use of this software
13 .\" must display the following acknowledgement:
14 .\" This product includes software developed by the University of
15 .\" California, Berkeley and its contributors.
16 .\" 4. Neither the name of the University nor the names of its contributors
17 .\" may be used to endorse or promote products derived from this software
18 .\" without specific prior written permission.
20 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 .\" @(#)1.6.t 8.1 (Berkeley) 6/8/93
34 .sh "Resource controls
38 The system gives CPU scheduling priority to processes that have not used
39 CPU time recently. This tends to favor interactive processes and
40 processes that execute only for short periods.
41 It is possible to determine the priority currently
42 assigned to a process, process group, or the processes of a specified user,
43 or to alter this priority using the calls:
46 #define PRIO_PROCESS 0 /* process */
47 #define PRIO_PGRP 1 /* process group */
48 #define PRIO_USER 2 /* user id */
50 prio = getpriority(which, who);
51 result int prio; int which, who;
53 setpriority(which, who, prio);
56 The value \fIprio\fP is in the range \-20 to 20.
57 The default priority is 0; lower priorities cause more
59 The \fIgetpriority\fP call returns the highest priority (lowest numerical value)
60 enjoyed by any of the specified processes.
61 The \fIsetpriority\fP call sets the priorities of all of the
62 specified processes to the specified value.
63 Only the super-user may lower priorities.
67 The resources used by a process are returned by a \fIgetrusage\fP call,
68 returning information in a structure defined in \fI<sys/resource.h>\fP:
71 #define RUSAGE_SELF 0 /* usage by this process */
72 #define RUSAGE_CHILDREN -1 /* usage by all children */
74 getrusage(who, rusage)
75 int who; result struct rusage *rusage;
79 struct timeval ru_utime; /* user time used */
80 struct timeval ru_stime; /* system time used */
81 int ru_maxrss; /* maximum core resident set size: kbytes */
82 int ru_ixrss; /* integral shared memory size (kbytes*sec) */
83 int ru_idrss; /* unshared data memory size */
84 int ru_isrss; /* unshared stack memory size */
85 int ru_minflt; /* page-reclaims */
86 int ru_majflt; /* page faults */
87 int ru_nswap; /* swaps */
88 int ru_inblock; /* block input operations */
89 int ru_oublock; /* block output operations */
90 int ru_msgsnd; /* messages sent */
91 int ru_msgrcv; /* messages received */
92 int ru_nsignals; /* signals received */
93 int ru_nvcsw; /* voluntary context switches */
94 int ru_nivcsw; /* involuntary context switches */
97 The \fIwho\fP parameter specifies whose resource usage is to be returned.
98 The resources used by the current process, or by all
99 the terminated children of the current process may be requested.
103 The resources of a process for which limits are controlled by the
104 kernel are defined in \fI<sys/resource.h>\fP, and controlled by the
105 \fIgetrlimit\fP and \fIsetrlimit\fP calls:
108 #define RLIMIT_CPU 0 /* cpu time in milliseconds */
109 #define RLIMIT_FSIZE 1 /* maximum file size */
110 #define RLIMIT_DATA 2 /* maximum data segment size */
111 #define RLIMIT_STACK 3 /* maximum stack segment size */
112 #define RLIMIT_CORE 4 /* maximum core file size */
113 #define RLIMIT_RSS 5 /* maximum resident set size */
115 #define RLIM_NLIMITS 6
117 #define RLIM_INFINITY 0x7f\&f\&f\&f\&f\&f\&f
121 int rlim_cur; /* current (soft) limit */
122 int rlim_max; /* hard limit */
125 getrlimit(resource, rlp)
126 int resource; result struct rlimit *rlp;
128 setrlimit(resource, rlp)
129 int resource; struct rlimit *rlp;
132 Only the super-user can raise the maximum limits.
134 alter \fIrlim_cur\fP within the range from 0 to \fIrlim_max\fP
135 or (irreversibly) lower \fIrlim_max\fP.