The man page for nice
says "nice() adds inc to the nice value for the calling process. So, can we use it to change the nice value for a t
The pthreads man page says:
POSIX.1 also requires that threads share a range of other attributes (i.e., these attributes are process-wide rather than per-thread):
[...]
- nice value (
setpriority
(2))
So, theoretically, the "niceness" value is global to the process and shared by all threads, and you should not be able to set a specific niceness for one or more individual threads.
However, the very same man page also says:
LinuxThreads
The notable features of this implementation are the following:
[...]
- Threads do not share a common nice value.
NPTL
[...]
NPTL still has a few non-conformances with POSIX.1:
- Threads do not share a common nice value.
So it turns out that both threading implementations on Linux (LinuxThreads and NPTL) actually violate POSIX.1, and you can set a specific niceness for one or more individual threads by passing a tid
to setpriority() on these systems.