Description Usage Arguments Details References Examples
Get/set the process's CPU affinity mask. The affinity mask binds the process to specific core(s) within the machine. Not supported on all systems, [has_affinity()] shows if this is available.
1 2 3 4 5 6 7 8 9 | setaffinity(cpus = 1:ncores())
getaffinity_count()
getaffinity()
has_affinity()
ncores()
|
cpus |
Which cpu cores to bind to: vector of integers between 1 and [ncores()] |
Setting a process afinity allows for restricting the process to only use certain cores in the machine. The cores are indexed by the operating system as 1 to [ncores()]. Calling [setaffinity()] with no arguments resets the process to use any of the available cores.
Note that setaffinity is different from setting r_limit values in the sense that it is not a one-way process. An unprivileged user can change the process affinity to any value. In order to 'lock' an affinity value, one would have to manipulate Linux capability value for CAP_SYS_NICE.
[SCHED_SETAFFINITY(2)](http://man7.org/linux/man-pages/man2/sched_setaffinity.2.html)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | ## Not run:
# Current affinity
ncores()
getaffinity()
getaffinity_count()
# Restrict process to core number 1.
setaffinity(1)
getaffinity()
# Reset
setaffinity()
getaffinity()
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.