Archive
 < October 2021 >
SunMonTueWedThuFriSat
262728293012
3456789
10111213141516
17181920212223
24252627282930
31123456
Monthly

## Programmatically Setting Processor Affinity

Aug18

Written by:David Aldridge
8/18/2010 9:41 PM

Sometimes it can be useful to restrict a program to just a single core or processor in a multicore system.  Sometimes you need to modify a program because it won't use all of the available cores.

The problem I had was with a program called SAM broadcaster - on my AMD system it was only utilizing one core.  I knew I could use task manager to set the cores for it to use (processor affinity) but I didn't want to do this every time.

I wanted a way to adjust the shortcut to make it set that every time.

Turns out what you need to use is a switch on the the start command:

cmd.exe /c "start /affinity 3 C:\path\to\your.exe"
The number after /affinity is a binary mask denoting which cores to use expressed as a hex number.  So for dual cores use 3, for tri cores use 7 and for quad cores use F.

To restrict it to a single core set it to just the bit that represents the core - so 1 for 1, 2 for 2, 4 for 3, 8 for 4 etc.

Tags: