Anything related to processor affinity, also known as CPU pinning. The processor affinity is a propriety of a process or a thread in an OS on multi-processor or multi-core systems that influences the OS' scheduling algorithm, binding the execution of that process (or thread) to a specific processor (or core). DO NOT use this tag as a synonym for [affinetransform] tag.
Questions tagged [affinity]
330 questions
44
votes
6 answers
How to set CPU affinity for a process from C or C++ in Linux?
Is there a programmatic method to set CPU affinity for a process in c/c++ for the Linux operating system?

jcodeninja
- 2,155
- 4
- 17
- 14
41
votes
2 answers
Setting "task affinity" programmatically
is there a way to set the "task affinity" programmatically? I mean like with some Intent flag or sth? I didn't find anything about this being possible in the Android docs.
Setting the affinity in a static way in the AndroidManifest.xml with…

aMiGo
- 757
- 7
- 10
38
votes
1 answer
How to reserve a core exclusively for a process
Possible Duplicate:
how to set CPU affinity of a particular pthread?
Is there a way in Linux to disable one core for all processes except one process? I would like to have one core reserved only and only for my process.
Expected behavior is as…

Kornel Szymkiewicz
- 582
- 1
- 6
- 12
28
votes
3 answers
Set affinity with start /AFFINITY command on Windows 7
I am using the start /AFFINITY [n] [.exe] command to start an executable with the specified affinity. I have a system with 8 processors (1,2,3,4,5,6,7,8). I'd like to set the process to use all of the odd processors (1,3,5,7). I cannot figure out…

bradvido
- 2,743
- 7
- 32
- 49
28
votes
2 answers
What is the difference between pthread_self() and gettid()? Which one should I use?
I'm trying to set the CPU affinity of threads on Linux. I'd like to know which one of the following approaches is recommended:
Get thread id using pthread_self()
Set CPU affinity using pthread_setaffinity_np(....) by passing the thread id as an…

roelf
- 361
- 2
- 4
- 5
26
votes
1 answer
Assigning a cpu core to a process - Linux
Is there any way to force a process with specific PID, to be executed and run on only one of the cpu s of a server? I know that there is a command like this
taskset -cp
but the above command does not work on my system. So please…

Admia
- 1,025
- 3
- 12
- 24
22
votes
6 answers
Linux find out Hyper-threaded core id
I spent this morning trying to find out how to determine which processor id is the hyper-threaded core, but without luck.
I wish to find out this information and use set_affinity() to bind a process to hyper-threaded thread or non-hyper-threaded…

Patrick
- 4,186
- 9
- 32
- 45
20
votes
1 answer
How to determine which logical cores share the same physical core?
I am working on a tool to allow students to self-evaluate their programming assignment's performance. In particular, the program they're writing is multi-threaded and I have no direct way of influencing the number of threads created. I would like to…

Tom van der Zanden
- 622
- 3
- 15
20
votes
4 answers
Change affinity of process with windows script
In Windows, with
START /node 1 /affinity ff cmd /C "app.exe"
I can set the affinity of app.exe (number of cores used by app.exe).
With a windows script, How I can change the affinity of a running process ?

JuanPablo
- 23,792
- 39
- 118
- 164
19
votes
3 answers
How to use sched_getaffinity and sched_setaffinity in Linux from C?
I am trying to:
Run 16 copies concurrently with processor pinning (2 copies per core)
Run 8 copies concurrently with processor pinning (2 copies per core) and flipping processor core to the furthest core after certain function say function 1…

Basmah
- 829
- 3
- 13
- 25
16
votes
1 answer
Why does using taskset to run a multi-threaded Linux program on a set of isolated cores cause all threads to run on one core?
Desired behaviour: run a multi-threaded Linux program on a set of cores which have been isolated using isolcpus.
Here's a small program we can use as an example multi-threaded program:
#include
#include
#include…

Edd Barrett
- 3,425
- 2
- 29
- 48
12
votes
1 answer
Set thread processor affinity in Microsoft .Net
(Posting this with answer because I couldn't find a full explanation of how to do this anywhere, so I thought it might have some value for someone)
How can I set the processor affinity of a particular thread in Microsoft .Net? Setting the process's…

Sven
- 21,903
- 4
- 56
- 63
11
votes
1 answer
Python 3.6.0: 'os' module does not have 'sched_getaffinity' method
I am trying to check the number of cores my script is using with 'os.sched_getaffinity' method as suggested in Why does multiprocessing use only a single core after I import numpy?. But when I run
import os
os.sched_getaffinity(0)
I…

Aki
- 155
- 1
- 2
- 8
11
votes
3 answers
Cannot avoid context-switches on a process launched alone on a CPU
I am investigating how run a process on a dedicated CPU in order to avoid context-switches. On my Ubuntu, I isolated two CPUs using the kernel parameters "isolcpus=3,7" and "irqaffinity=0-2,4-6". I am sure that it is correctly taken into account:
$…

Philippe MESMEUR
- 737
- 8
- 22
10
votes
8 answers
How to set processor affinity on an executable in Windows XP?
I have a quad core system with third party application that once in a while spins several processes (always the same executable but several instances of it) and takes 100% of CPU time. I also have a couple of web services running on the same box…

bychkov
- 1,503
- 1
- 13
- 26