2 .\" Copyright (c) 2008, Sun Microsystems, Inc. All Rights Reserved.
3 .\" Copyright (c) 1980 Regents of the University of California. All rights reserved. The Berkeley software License Agreement specifies the terms and conditions for redistribution.
4 .\" Portions Copyright (c) 1992, X/Open Company Limited All Rights Reserved.
5 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation. Original documentation from The Open Group can be obtained online at
6 .\" http://www.opengroup.org/bookstore/.
7 .\" The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation. In the following statement, the phrase "this text" refers to portions of the system documentation. Portions of this text are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between these versions and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html.
8 .\" This notice shall appear on any product containing this material.
9 .TH GETPRIORITY 3C "Apr 1, 2008"
11 getpriority, setpriority \- get and set the nice value
15 #include <sys/resource.h>
17 \fBint\fR \fBgetpriority\fR(\fBint\fR \fIwhich\fR, \fBid_t\fR \fIwho\fR);
22 \fBint\fR \fBsetpriority\fR(\fBint\fR \fIwhich\fR, \fBid_t\fR \fIwho\fR, \fBint\fR \fIvalue\fR);
28 The \fBgetpriority()\fR function obtains the nice value of a process, thread,
29 or set of processes. The \fBsetpriority()\fR function sets the nice value of a
30 process, thread, or set of processes to \fIvalue\fR+\fBNZERO\fR, where
31 \fBNZERO\fR is defined to be 20.
34 Target entities are specified by the values of the \fIwhich\fR and \fIwho\fR
35 arguments. The \fIwhich\fR argument can be one of the following values:
36 \fBPRIO_PROCESS\fR, \fBPRIO_PGRP\fR, \fBPRIO_USER\fR, \fBPRIO_GROUP\fR,
37 \fBPRIO_SESSION\fR, \fBPRIO_LWP\fR, \fBPRIO_TASK\fR, \fBPRIO_PROJECT\fR,
38 \fBPRIO_ZONE\fR, or \fBPRIO_CONTRACT\fR, indicating that the \fIwho\fR argument
39 is to be interpreted as a process ID, a process group ID, an effective user ID,
40 an effective group ID, a session ID, a thread (lwp) ID, a task ID, a project
41 ID, a zone ID, or a process contract ID, respectively. A 0 value for the
42 \fIwho\fR argument specifies the current process, process group, or user. A 0
43 value for the \fIwho\fR argument is treated as valid group ID, session ID,
44 thread (lwp) ID, task ID, project ID, zone ID, or process contract ID. A
45 \fBP_MYID\fR value for the \fIwho\fR argument can be used to specify the
46 current group, session, thread, task, project, zone, or process contract,
50 If a specified process is multi-threaded, the nice value set with
51 \fBsetpriority()\fR affects all threads in the process.
54 If more than one process is specified, \fBgetpriority()\fR returns \fBNZERO\fR
55 less than the lowest nice value pertaining to any of the specified entities,
56 and \fBsetpriority()\fR sets the nice values of all of the specified processes
57 to \fIvalue\fR+\fBNZERO\fR.
60 The default nice value is \fBNZERO\fR. Lower nice values cause more favorable
61 scheduling. The range of valid nice values is 0 to \fBNZERO\fR*2-1. If
62 \fIvalue\fR+\fBNZERO\fR is less than the system's lowest supported nice value,
63 \fBsetpriority()\fR sets the nice value to the lowest supported value. If
64 \fIvalue\fR+\fBNZERO\fR is greater than the system's highest supported nice
65 value, \fBsetpriority()\fR sets the nice value to the highest supported value.
68 Only a process with appropriate privileges can lower the nice value.
71 Any process or thread using \fBSCHED_FIFO\fR or \fBSCHED_RR\fR is unaffected by
72 a call to \fBsetpriority()\fR. This is not considered an error. A process or
73 thread that subsequently reverts to \fBSCHED_OTHER\fR will not have its
74 priority affected by such a \fBsetpriority()\fR call.
77 The effect of changing the nice value varies depending on the scheduling policy
81 Since \fBgetpriority()\fR can return the value -1 on successful completion, it
82 is necessary to set \fBerrno\fR to 0 prior to a call to \fBgetpriority()\fR. If
83 \fBgetpriority()\fR returns the value -1, then \fBerrno\fR can be checked to
84 see if an error occurred or if the value is a legitimate nice value.
88 Upon successful completion, \fBgetpriority()\fR returns an integer in the range
89 from -\fBNZERO\fR to \fBNZERO\fR-1. Otherwise, \fB\(mi1\fR is returned and
90 \fBerrno\fR is set to indicate the error.
93 Upon successful completion, \fBsetpriority()\fR returns \fB0\fR. Otherwise,
94 \fB\(mi1\fR is returned and \fBerrno\fR is set to indicate the error.
98 The \fBgetpriority()\fR and \fBsetpriority()\fR functions will fail if:
105 No process or thread could be located using the \fIwhich\fR and \fIwho\fR
106 argument values specified.
115 The value of the \fIwhich\fR argument was not recognized, or the value of the
116 \fIwho\fR argument is not a valid process ID, process group ID, user ID, group
117 ID, session ID, thread (lwp) ID, task ID, project ID, or zone ID.
122 In addition, \fBsetpriority()\fR may fail if:
129 A process was located, but neither the real nor effective user ID of the
130 executing process match the effective user ID of the process whose nice value
140 A request was made to change the nice value to a lower numeric value and the
141 current process does not have appropriate privileges.
146 \fBExample 1 \fRExample using \fBgetpriority()\fR
149 The following example returns the current scheduling priority for the process
150 ID returned by the call to \fBgetpid\fR(2).
155 #include <sys/resource.h>
157 int which = PRIO_PROCESS;
162 ret = getpriority(which, pid);
167 \fBExample 2 \fRExample using \fBsetpriority()\fR
170 The following example sets the nice value for the current process to 0.
175 #include <sys/resource.h>
177 int which = PRIO_PROCESS;
183 ret = setpriority(which, pid, value);
190 The \fBgetpriority()\fR and \fBsetpriority()\fR functions work with an offset
191 nice value (\fIvalue\fR-\fBNZERO\fR). The nice value is in the range 0 to
192 2*\fBNZERO\fR-1, while the return value for \fBgetpriority()\fR and the third
193 parameter for \fBsetpriority()\fR are in the range -\fBNZERO\fR to
198 See \fBattributes\fR(5) for descriptions of the following attributes:
206 ATTRIBUTE TYPE ATTRIBUTE VALUE
208 Interface Stability Committed
210 Standard See \fBstandards\fR(5).
216 \fBnice\fR(1), \fBrenice\fR(1), \fBsched_get_priority_max\fR(3C),
217 \fBsched_setscheduler\fR(3C), \fBattributes\fR(5), \fBstandards\fR(5)