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. Neither the name of the University nor the names of its contributors
13 .\" may be used to endorse or promote products derived from this software
14 .\" without specific prior written permission.
16 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 .sh "Resource controls
32 The system gives CPU scheduling priority to processes that have not used
33 CPU time recently. This tends to favor interactive processes and
34 processes that execute only for short periods.
35 It is possible to determine the priority currently
36 assigned to a process, process group, or the processes of a specified user,
37 or to alter this priority using the calls:
40 #define PRIO_PROCESS 0 /* process */
41 #define PRIO_PGRP 1 /* process group */
42 #define PRIO_USER 2 /* user id */
44 prio = getpriority(which, who);
45 result int prio; int which, who;
47 setpriority(which, who, prio);
50 The value \fIprio\fP is in the range \-20 to 20.
51 The default priority is 0; lower priorities cause more
53 The \fIgetpriority\fP call returns the highest priority (lowest numerical value)
54 enjoyed by any of the specified processes.
55 The \fIsetpriority\fP call sets the priorities of all of the
56 specified processes to the specified value.
57 Only the super-user may lower priorities.
61 The resources used by a process are returned by a \fIgetrusage\fP call,
62 returning information in a structure defined in \fI<sys/resource.h>\fP:
65 #define RUSAGE_SELF 0 /* usage by this process */
66 #define RUSAGE_CHILDREN -1 /* usage by all children */
68 getrusage(who, rusage)
69 int who; result struct rusage *rusage;
73 struct timeval ru_utime; /* user time used */
74 struct timeval ru_stime; /* system time used */
75 int ru_maxrss; /* maximum core resident set size: kbytes */
76 int ru_ixrss; /* integral shared memory size (kbytes*sec) */
77 int ru_idrss; /* unshared data memory size */
78 int ru_isrss; /* unshared stack memory size */
79 int ru_minflt; /* page-reclaims */
80 int ru_majflt; /* page faults */
81 int ru_nswap; /* swaps */
82 int ru_inblock; /* block input operations */
83 int ru_oublock; /* block output operations */
84 int ru_msgsnd; /* messages sent */
85 int ru_msgrcv; /* messages received */
86 int ru_nsignals; /* signals received */
87 int ru_nvcsw; /* voluntary context switches */
88 int ru_nivcsw; /* involuntary context switches */
91 The \fIwho\fP parameter specifies whose resource usage is to be returned.
92 The resources used by the current process, or by all
93 the terminated children of the current process may be requested.
97 The resources of a process for which limits are controlled by the
98 kernel are defined in \fI<sys/resource.h>\fP, and controlled by the
99 \fIgetrlimit\fP and \fIsetrlimit\fP calls:
102 #define RLIMIT_CPU 0 /* cpu time in milliseconds */
103 #define RLIMIT_FSIZE 1 /* maximum file size */
104 #define RLIMIT_DATA 2 /* maximum data segment size */
105 #define RLIMIT_STACK 3 /* maximum stack segment size */
106 #define RLIMIT_CORE 4 /* maximum core file size */
107 #define RLIMIT_RSS 5 /* maximum resident set size */
109 #define RLIM_NLIMITS 6
111 #define RLIM_INFINITY 0x7f\&f\&f\&f\&f\&f\&f
115 int rlim_cur; /* current (soft) limit */
116 int rlim_max; /* hard limit */
119 getrlimit(resource, rlp)
120 int resource; result struct rlimit *rlp;
122 setrlimit(resource, rlp)
123 int resource; struct rlimit *rlp;
126 Only the super-user can raise the maximum limits.
128 alter \fIrlim_cur\fP within the range from 0 to \fIrlim_max\fP
129 or (irreversibly) lower \fIrlim_max\fP.