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