2
I wrote code to set the affinity of every process under my username to core 0 only. I ran this code, and then it exited once it was finished.
Then, even when I launched a brand new terminal, and opened python with it, its affinity was still fixed to core 0. The expected default behaviour would be for the newly launched python shell to have affinity to both core 0 and core 1 of course.
It's not the case that there's something causing all python processes to have the same CPU affinity either -- I verified this by setting two different python processes to two different cores.
Another experiment I ran is to set the affinity of only python processes to core 0 (all other processes untouched). Then, when I launched a new python shell, its affinity was still normal (not fixed to only 0). This suggest that there's some special non-python process which is governing the CPU affinity of new python processes.
My question is: what is this special process?
For reference, for setting and checking CPU affinity, I used psutil.Process.cpu_affinity
from python's psutil
library.
2If you wrote code, to set the affinity of every process to core 0, why are you shocked that new python processes are set to core 0? – Ramhound – 2017-12-02T16:48:19.210
Because I set the affinity of every existing process to core 0 -- which shouldn't have any effect on the affinity of any new processes started afterwards. The code can't have touched the affinity of any new processes because those processes didn't exist at the time the code was run. – shimao – 2017-12-02T16:50:16.823
4If you managed to set the affinity of every process to 0, then any child processes (of whatever lauched python or your terminal) may well inherit that affinity. If you only wanted it to affect the terminal that launched python, then you should only have changed that terminal affinity – Mokubai – 2017-12-02T17:10:58.243
1I see. I confirmed this out for myself and found that bash was being launched from xfterminal, which is itself a child of xfsettingsd, which is a child of the init process. xfsettingsd had its affinity set to 0, which explains everything. – shimao – 2017-12-02T17:35:02.840