NICE(3P)
πΈ NICE(3P) πΈ
okay bestie, so this is NICE(3P), straight out of the POSIX Programmer's Manual, and it's lowkey the origin story of "hey, can u chill a sec" for your processes π
π«Ά PROLOG
So real talk: this manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ β so if you're on Linux, go consult the corresponding Linux manual page for the deets on Linux behavior. And plot twist: the interface might not even be implemented on Linux at all. π Not every baddie makes it to every platform, iykyk.
β¨ NAME
nice β change the nice value of a process π
π» SYNOPSIS
#include <unistd.h>
int nice(int incr);
π DESCRIPTION
okay so here's the vibe: the nice() function shall add the value of incr to the nice value of the calling process. And what even is a nice value? It's a non-negative number, and the more positive it gets, the less favorable your scheduling becomes. so like... being "nice" is literally the sacrifice mechanic. you're giving up CPU time out of the goodness of your heart. iconic behavior honestly π
The system imposes a maximum nice value of 2*{NZERO}-1 and a minimum nice value of 0. Ask for something above or below those limits and the nice value just gets set to the corresponding limit β the system is NOT negotiating, periodt.
β οΈ Only a process with appropriate privileges can lower the nice value. so you can make yourself nicer for free, but un-nice-ing yourself? that's a privilege thing bestie, don't try it without the credentials π
Calling the nice() function has no effect on the priority of processes or threads with policy SCHED_FIFO or SCHED_RR. For processes or threads with other scheduling policies, the effect is implementation-defined. (mysterious. unknowable. very much "it depends" energy β¨)
The nice value set with nice() shall be applied to the process. And if the process is multi-threaded? the nice value shall affect all system scope threads in the process. everybody eats together π«Ά
and now the classic gotcha, the one that gets everybody: since -1 is a permissible return value in a successful situation, if you're an application wishing to check for error situations, you should set errno to 0, then call nice(), and if it returns -1, check to see whether errno is non-zero. like, set errno to 0 FIRST. do not skip that step. this is the whole plot of the movie π
β RETURN VALUE
Upon successful completion, nice() shall return the new nice value -{NZERO}. π
Otherwise, -1 shall be returned, the nice value of the process shall not be changed, and errno shall be set to indicate the error. (no change, no cap, no nice β just an error code and a lesson π)
π₯ ERRORS
The nice() function shall fail if:
EPERMβ Theincrargument is negative and the calling process does not have appropriate privileges. π so you tried to lower the nice value without the clearance and the system said "absolutely not, ma'am."
The following sections are informative. (translation: the lore is over, everything from here on is bonus content π)
π EXAMPLES
π§ Changing the Nice Value
The following example adds the value of the incr argument, -20, to the nice value of the calling process:
#include <unistd.h>
...
int incr = -20;
int ret;
ret = nice(incr);
look at her go. one little call, one big scheduling mood shift β¨
π APPLICATION USAGE
None.
(that's it. nothing. empty. the void. honestly? respect π)
πΈ RATIONALE
None.
π¦ FUTURE DIRECTIONS
None.
π SEE ALSO
exec,getpriority()- The Base Definitions volume of POSIX.1β2017,
<limits.h>,<unistd.h>
π COPYRIGHT
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version 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 .
Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .
and that's the whole page bestie!! brought to you by IEEE/The Open Group, dated 2017, and yes the manual is literally called NICE(3P) π
go be nice to your scheduler, she's doing her best π«Άβ¨
π¦ where this page comes from
- alpine 3.22: man-pages-posix 2017a-r0 Β· custom
- alpine 3.23: man-pages-posix 2017a-r0 Β· custom
- alpine 3.24: man-pages-posix 2017a-r0 Β· custom
- arch rolling: man-pages 6.19-1
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages-posix 2017a
- opensuse-leap 16.0: man-pages-posix 2017a-160000.4.1 Β· SUSE-IEEE
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms