Start of man-pages-5.14: renaming .Announce and .lsm files
[man-pages.git] / man2 / nice.2
blob9bcd34e9e766e7d24c9ba1d00aa17f12909266de
1 .\" Copyright (c) 1992 Drew Eckhardt <drew@cs.colorado.edu>, March 28, 1992
2 .\"
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein.  The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .\" Modified by Michael Haardt <michael@moria.de>
26 .\" Modified 1993-07-24 by Rik Faith <faith@cs.unc.edu>
27 .\" Modified 1996-11-04 by Eric S. Raymond <esr@thyrsus.com>
28 .\" Modified 2001-06-04 by aeb
29 .\" Modified 2004-05-27 by Michael Kerrisk <mtk.manpages@gmail.com>
30 .\"
31 .TH NICE 2 2021-03-22 "Linux" "Linux Programmer's Manual"
32 .SH NAME
33 nice \- change process priority
34 .SH SYNOPSIS
35 .nf
36 .B #include <unistd.h>
37 .PP
38 .BI "int nice(int " inc );
39 .fi
40 .PP
41 .RS -4
42 Feature Test Macro Requirements for glibc (see
43 .BR feature_test_macros (7)):
44 .RE
45 .PP
46 .BR nice ():
47 .nf
48     _XOPEN_SOURCE
49         || /* Since glibc 2.19: */ _DEFAULT_SOURCE
50         || /* Glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
51 .fi
52 .SH DESCRIPTION
53 .BR nice ()
54 adds
55 .I inc
56 to the nice value for the calling thread.
57 (A higher nice value means a lower priority.)
58 .PP
59 The range of the nice value is +19 (low priority) to \-20 (high priority).
60 Attempts to set a nice value outside the range are clamped to the range.
61 .PP
62 Traditionally, only a privileged process could lower the nice value
63 (i.e., set a higher priority).
64 However, since Linux 2.6.12, an unprivileged process can decrease
65 the nice value of a target process that has a suitable
66 .BR RLIMIT_NICE
67 soft limit; see
68 .BR getrlimit (2)
69 for details.
70 .SH RETURN VALUE
71 On success, the new nice value is returned (but see NOTES below).
72 On error, \-1 is returned, and
73 .I errno
74 is set to indicate the error.
75 .PP
76 A successful call can legitimately return \-1.
77 To detect an error, set
78 .I errno
79 to 0 before the call, and check whether it is nonzero after
80 .BR nice ()
81 returns \-1.
82 .SH ERRORS
83 .TP
84 .B EPERM
85 The calling process attempted to increase its priority by
86 supplying a negative
87 .I inc
88 but has insufficient privileges.
89 Under Linux, the
90 .B CAP_SYS_NICE
91 capability is required.
92 (But see the discussion of the
93 .B RLIMIT_NICE
94 resource limit in
95 .BR setrlimit (2).)
96 .SH CONFORMING TO
97 POSIX.1-2001, POSIX.1-2008, SVr4, 4.3BSD.
98 However, the raw system call and (g)libc
99 (earlier than glibc 2.2.4) return value is nonstandard, see below.
100 .\" SVr4 documents an additional
101 .\" .B EINVAL
102 .\" error code.
103 .SH NOTES
104 For further details on the nice value, see
105 .BR sched (7).
107 .IR Note :
108 the addition of the "autogroup" feature in Linux 2.6.38 means that
109 the nice value no longer has its traditional effect in many circumstances.
110 For details, see
111 .BR sched (7).
113 .SS C library/kernel differences
114 POSIX.1 specifies that
115 .BR nice ()
116 should return the new nice value.
117 However, the raw Linux system call returns 0 on success.
118 Likewise, the
119 .BR nice ()
120 wrapper function provided in glibc 2.2.3 and earlier returns 0 on success.
122 Since glibc 2.2.4, the
123 .BR nice ()
124 wrapper function provided by glibc provides conformance to POSIX.1 by calling
125 .BR getpriority (2)
126 to obtain the new nice value, which is then returned to the caller.
127 .SH SEE ALSO
128 .BR nice (1),
129 .BR renice (1),
130 .BR fork (2),
131 .BR getpriority (2),
132 .BR getrlimit (2),
133 .BR setpriority (2),
134 .BR capabilities (7),
135 .BR sched (7)