xref: /netbsd-src/lib/libc/sys/getpriority.2 (revision d710132b4b8ce7f7cccaaf660cb16aa16b4077a0)
1.\"	$NetBSD: getpriority.2,v 1.14 2003/04/16 13:34:52 wiz Exp $
2.\"
3.\" Copyright (c) 1980, 1991, 1993
4.\"	The Regents of the University of California.  All rights reserved.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright
10.\"    notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\"    notice, this list of conditions and the following disclaimer in the
13.\"    documentation and/or other materials provided with the distribution.
14.\" 3. All advertising materials mentioning features or use of this software
15.\"    must display the following acknowledgement:
16.\"	This product includes software developed by the University of
17.\"	California, Berkeley and its contributors.
18.\" 4. Neither the name of the University nor the names of its contributors
19.\"    may be used to endorse or promote products derived from this software
20.\"    without specific prior written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE.
33.\"
34.\"     @(#)getpriority.2	8.1 (Berkeley) 6/4/93
35.\"
36.Dd June 4, 1993
37.Dt GETPRIORITY 2
38.Os
39.Sh NAME
40.Nm getpriority ,
41.Nm setpriority
42.Nd get/set program scheduling priority
43.Sh LIBRARY
44.Lb libc
45.Sh SYNOPSIS
46.In sys/resource.h
47.Ft int
48.Fn getpriority "int which" "int who"
49.Ft int
50.Fn setpriority "int which" "int who" "int prio"
51.Sh DESCRIPTION
52The scheduling
53priority of the process, process group, or user, as indicated by
54.Fa which
55and
56.Fa who
57is obtained with the
58.Fn getpriority
59call and set with the
60.Fn setpriority
61call.
62.Fa which
63is one of
64.Dv PRIO_PROCESS ,
65.Dv PRIO_PGRP ,
66or
67.Dv PRIO_USER ,
68and
69.Fa who
70is interpreted relative to
71.Fa which
72(a process identifier for
73.Dv PRIO_PROCESS ,
74process group
75identifier for
76.Dv PRIO_PGRP ,
77and a user ID for
78.Dv PRIO_USER ) .
79A zero value of
80.Fa who
81denotes the current process, process group, or user.
82.Fa prio
83is a value in the range -20 to 20.
84The default priority is 0;
85lower priorities cause more favorable scheduling.
86A value of 19 or 20
87will schedule a process only when nothing at priority \*(Le 0 is runnable.
88.Pp
89The
90.Fn getpriority
91call returns the highest priority (lowest numerical value)
92enjoyed by any of the specified processes.
93The
94.Fn setpriority
95call sets the priorities of all of the specified processes
96to the specified value.
97Only the super-user may lower priorities.
98.Sh RETURN VALUES
99Since
100.Fn getpriority
101can legitimately return the value -1, it is necessary
102to clear the external variable
103.Va errno
104prior to the
105call, then check it afterward to determine
106if a -1 is an error or a legitimate value.
107The
108.Fn setpriority
109call returns 0 if there is no error, or
110-1 if there is.
111.Sh ERRORS
112.Fn getpriority
113and
114.Fn setpriority
115will fail if:
116.Bl -tag -width Er
117.It Bq Er ESRCH
118No process was located using the
119.Fa which
120and
121.Fa who
122values specified.
123.It Bq Er EINVAL
124.Fa which
125was not one of
126.Dv PRIO_PROCESS ,
127.Dv PRIO_PGRP ,
128or
129.Dv PRIO_USER .
130.El
131.Pp
132.Bl -tag -width Er
133In addition to the errors indicated above,
134.Fn setpriority
135will fail if:
136.It Bq Er EPERM
137A process was located, but neither its effective nor real user
138ID matched the effective user ID of the caller.
139.It Bq Er EACCES
140A non super-user attempted to lower a process priority.
141.El
142.Sh SEE ALSO
143.Xr nice 1 ,
144.Xr fork 2 ,
145.Xr renice 8
146.Sh HISTORY
147The
148.Fn getpriority
149function call appeared in
150.Bx 4.2 .
151