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