SCCS id got lost along the way
[unix-history] / usr / src / lib / libc / sys / getpriority.2
CommitLineData
931b8415 1.\" Copyright (c) 1980, 1991 The Regents of the University of California.
88b3ccf2 2.\" All rights reserved.
e08c6f11 3.\"
91cff1e1 4.\" %sccs.include.redist.man%
88b3ccf2 5.\"
931b8415 6.\" @(#)getpriority.2 6.9 (Berkeley) %G%
e08c6f11 7.\"
931b8415
CL
8.Dd
9.Dt GETPRIORITY 2
10.Os BSD 4
11.Sh NAME
12.Nm getpriority ,
13.Nm setpriority
14.Nd get/set program scheduling priority
15.Sh SYNOPSIS
16.Fd #include <sys/time.h>
17.Fd #include <sys/resource.h>
18.Ft int
19.Fn getpriority "int which" "int who"
20.Ft int
21.Fn setpriority "int which" "int who" "int prio"
22.Sh DESCRIPTION
e08c6f11 23The scheduling
e0304aa6 24priority of the process, process group, or user, as indicated by
931b8415 25.Fa which
e0304aa6 26and
931b8415 27.Fa who
e0304aa6 28is obtained with the
931b8415 29.Fn getpriority
e0304aa6 30call and set with the
931b8415 31.Fn setpriority
e0304aa6 32call.
931b8415
CL
33.Fa Which
34is one of
35.Dv PRIO_PROCESS ,
36.Dv PRIO_PGRP ,
37or
38.Dv PRIO_USER ,
39and
40.Fa who
e0304aa6 41is interpreted relative to
931b8415
CL
42.Fa which
43(a process identifier for
44.Dv PRIO_PROCESS ,
45process group
46identifier for
47.Dv PRIO_PGRP ,
48and a user ID for
49.Dv PRIO_USER ) .
f5c144bd 50A zero value of
931b8415 51.Fa who
f5c144bd 52denotes the current process, process group, or user.
931b8415
CL
53.Fa Prio
54is a value in the range -20 to 20. The default priority is 0;
e0304aa6 55lower priorities cause more favorable scheduling.
931b8415 56.Pp
e0304aa6 57The
931b8415 58.Fn getpriority
e0304aa6
KM
59call returns the highest priority (lowest numerical value)
60enjoyed by any of the specified processes. The
931b8415 61.Fn setpriority
e0304aa6
KM
62call sets the priorities of all of the specified processes
63to the specified value. Only the super-user may lower priorities.
931b8415 64.Sh RETURN VALUES
e0304aa6 65Since
931b8415
CL
66.Fn getpriority
67can legitimately return the value -1, it is necessary
68to clear the external variable
69.Va errno
70prior to the
e0304aa6 71call, then check it afterward to determine
931b8415 72if a -1 is an error or a legitimate value.
e0304aa6 73The
931b8415 74.Fn setpriority
e0304aa6 75call returns 0 if there is no error, or
931b8415
CL
76-1 if there is.
77.Sh ERRORS
78.Fn Getpriority
e0304aa6 79and
931b8415
CL
80.Fn setpriority
81will fail if:
82.Bl -tag -width Er
83.It Bq Er ESRCH
9b8a2ecf 84No process was located using the
931b8415 85.Fa which
e0304aa6 86and
931b8415 87.Fa who
e0304aa6 88values specified.
931b8415
CL
89.It Bq Er EINVAL
90.Fa Which
91was not one of
92.Dv PRIO_PROCESS ,
93.Dv PRIO_PGRP ,
94or
95.Dv PRIO_USER .
96.El
97.Pp
98.Bl -tag -width Er
e0304aa6 99In addition to the errors indicated above,
931b8415
CL
100.Fn setpriority
101will fail if:
102.It Bq Er EPERM
e0304aa6
KM
103A process was located, but neither its effective nor real user
104ID matched the effective user ID of the caller.
931b8415 105.It Bq Er EACCES
9b8a2ecf 106A non super-user attempted to lower a process priority.
931b8415
CL
107.El
108.Sh SEE ALSO
109.Xr nice 1 ,
110.Xr fork 2 ,
111.Xr renice 8
112.Sh HISTORY
113The
114.Nm
115function call appeared in
116.Bx 4.2 .