As I understand it, in Linux, threads and processes are almost the same; threads are simply processes that use the same memory, and do not do fork copy-on-write, and fork (2) and pthread_create (3) are supposedly both simply superimposed on the clone (2) call with different arguments.
The planning material is very confusing because, for example, pthreads (7) starts with a message that the Posix threads have a common pleasant value, but then you need to go to
NPTL still has some inconsistencies with POSIX. 1: Threads do not share an overall pleasant value
to see the whole picture (and I'm sure there are many more useful pages).
I wrote graphical applications that spawn many computational threads from the main user interface thread and always find the key to keep the application very responsive in order to call nice (2) in the computational threads (only); increasing it by 4 or so seems to work well.
Or at least what I remember. I just looked at the code for the first time in many years and saw that I actually did this:
Interestingly. I probably tried it well (2) and found that it really applies to the whole process (all threads), which I did not want (but maybe so). But this is already happening a few years ago; behavior may change since.
One important tool when you play with such things: if you press "H" (NB is not "h") at top (1) , it changes the look of the process, showing all threads and individual threads with good values. For example, if I run [evolvotron][7] -t 4 -n 5 (4 compute threads in nice 5), I see (I am on an old single-core machine other than HT, so this is actually not so much in several threads):
Tasks: 249 total, 5 running, 244 sleeping, 0 stopped, 0 zombie Cpu(s): 17.5%us, 6.3%sy, 76.2%ni, 0.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st Mem: 1025264k total, 984316k used, 40948k free, 96136k buffers Swap: 1646620k total, 0k used, 1646620k free, 388596k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 4911 local 25 5 81096 23m 15m R 19.7 2.4 0:04.03 evolvotron 4912 local 25 5 81096 23m 15m R 19.7 2.4 0:04.20 evolvotron 4913 local 25 5 81096 23m 15m R 19.7 2.4 0:04.08 evolvotron 4914 local 25 5 81096 23m 15m R 19.7 2.4 0:04.19 evolvotron 4910 local 20 0 81096 23m 15m S 9.8 2.4 0:05.83 evolvotron ...