xref: /original-bsd/lib/libc/sys/getpriority.2 (revision 4092c5cc)
1.\" Copyright (c) 1980, 1991, 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" %sccs.include.redist.man%
5.\"
6.\"     @(#)getpriority.2	8.1 (Berkeley) 06/04/93
7.\"
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
23The scheduling
24priority of the process, process group, or user, as indicated by
25.Fa which
26and
27.Fa who
28is obtained with the
29.Fn getpriority
30call and set with the
31.Fn setpriority
32call.
33.Fa Which
34is one of
35.Dv PRIO_PROCESS ,
36.Dv PRIO_PGRP ,
37or
38.Dv PRIO_USER ,
39and
40.Fa who
41is interpreted relative to
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 ) .
50A zero value of
51.Fa who
52denotes the current process, process group, or user.
53.Fa Prio
54is a value in the range -20 to 20.  The default priority is 0;
55lower priorities cause more favorable scheduling.
56.Pp
57The
58.Fn getpriority
59call returns the highest priority (lowest numerical value)
60enjoyed by any of the specified processes.  The
61.Fn setpriority
62call sets the priorities of all of the specified processes
63to the specified value.  Only the super-user may lower priorities.
64.Sh RETURN VALUES
65Since
66.Fn getpriority
67can legitimately return the value -1, it is necessary
68to clear the external variable
69.Va errno
70prior to the
71call, then check it afterward to determine
72if a -1 is an error or a legitimate value.
73The
74.Fn setpriority
75call returns 0 if there is no error, or
76-1 if there is.
77.Sh ERRORS
78.Fn Getpriority
79and
80.Fn setpriority
81will fail if:
82.Bl -tag -width Er
83.It Bq Er ESRCH
84No process was located using the
85.Fa which
86and
87.Fa who
88values specified.
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
99In addition to the errors indicated above,
100.Fn setpriority
101will fail if:
102.It Bq Er EPERM
103A process was located, but neither its effective nor real user
104ID matched the effective user ID of the caller.
105.It Bq Er EACCES
106A non super-user attempted to lower a process priority.
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 .
117