xref: /freebsd-13.1/lib/libc/sys/getpriority.2 (revision fbbd9655)
1.\" Copyright (c) 1980, 1991, 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
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.
15.\"
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
26.\" SUCH DAMAGE.
27.\"
28.\"     @(#)getpriority.2	8.1 (Berkeley) 6/4/93
29.\" $FreeBSD$
30.\"
31.Dd June 4, 1993
32.Dt GETPRIORITY 2
33.Os
34.Sh NAME
35.Nm getpriority ,
36.Nm setpriority
37.Nd get/set program scheduling priority
38.Sh LIBRARY
39.Lb libc
40.Sh SYNOPSIS
41.In sys/time.h
42.In sys/resource.h
43.Ft int
44.Fn getpriority "int which" "int who"
45.Ft int
46.Fn setpriority "int which" "int who" "int prio"
47.Sh DESCRIPTION
48The scheduling
49priority of the process, process group, or user, as indicated by
50.Fa which
51and
52.Fa who
53is obtained with the
54.Fn getpriority
55system call and set with the
56.Fn setpriority
57system call.
58The
59.Fa which
60argument
61is one of
62.Dv PRIO_PROCESS ,
63.Dv PRIO_PGRP ,
64or
65.Dv PRIO_USER ,
66and
67.Fa who
68is interpreted relative to
69.Fa which
70(a process identifier for
71.Dv PRIO_PROCESS ,
72process group
73identifier for
74.Dv PRIO_PGRP ,
75and a user ID for
76.Dv PRIO_USER ) .
77A zero value of
78.Fa who
79denotes the current process, process group, or user.
80The
81.Fa prio
82argument
83is a value in the range -20 to 20.
84The default priority is 0;
85lower priorities cause more favorable scheduling.
86.Pp
87The
88.Fn getpriority
89system call returns the highest priority (lowest numerical value)
90enjoyed by any of the specified processes.
91The
92.Fn setpriority
93system call sets the priorities of all of the specified processes
94to the specified value.
95Only the super-user may lower priorities.
96.Sh RETURN VALUES
97Since
98.Fn getpriority
99can legitimately return the value -1, it is necessary
100to clear the external variable
101.Va errno
102prior to the
103call, then check it afterward to determine
104if a -1 is an error or a legitimate value.
105.Pp
106.Rv -std setpriority
107.Sh ERRORS
108The
109.Fn getpriority
110and
111.Fn setpriority
112system calls
113will fail if:
114.Bl -tag -width Er
115.It Bq Er ESRCH
116No process was located using the
117.Fa which
118and
119.Fa who
120values specified.
121.It Bq Er EINVAL
122The
123.Fa which
124argument
125was not one of
126.Dv PRIO_PROCESS ,
127.Dv PRIO_PGRP ,
128or
129.Dv PRIO_USER .
130.El
131.Pp
132In addition to the errors indicated above,
133.Fn setpriority
134will fail if:
135.Bl -tag -width Er
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
149system call appeared in
150.Bx 4.2 .
151