How do I permanently set the affinity of a process?

39,810

Solution 1

You can create a shortcut to assign affinity.

X:\Windows\System32\cmd.exe /C start /affinity Y game.exe

Y is hexadecimal and is a bit mask:

0x1 - 0001 - Core0
0x2 - 0010 - Core1
0x3 - 0011 - Core1 & Core0
0x4 - 0100 - Core2
0x5 - 0101 - Core2 & Core0
0x6 - 0110 - Core2 & Core1
0x7 - 0111 - Core2 & Core1 & Core0
0x8 - 1000 - Core3
0x9 - 1001 - Core3 & Core0
0xA - 1010 - Core3 & Core1
0xB - 1011 - Core3 & Core1 & Core0
0xC - 1100 - Core3 & Core2
0xD - 1101 - Core3 & Core2 & Core0
0xE - 1110 - Core3 & Core2 & Core1
0xF - 1111 - Core3 & Core2 & Core1 & Core0

Solution 2

If by "non software" you mean not requiring additional software, there is. You can run the program from a command script and use the affinity switch "Start /AFFINITY 20 process.exe"

/AFFINITY 20treats the 20 as a hexidecimal number, with a binary equivalent of 100000, which sets affinity to core 5 out of 0-5 on a 6 core processor. A similar hex mask will let you disable a specific core, such as E, which only runs the process on cores 1-3 out of 0-3 or 0-5.

Solution 3

For anyone else looking for answers to this and not finding any, the solution I found was to use an app called WinAFC (or AffinityChanger). This is a partial GUI, partial command line app that allows you to specify profiles for certain executables, and will poll the process list for them. If it finds matching processes, it will change the affinity of those processes according to the settings in the loaded profile.

There is some documentation here: http://affinitychanger.sourceforge.net/

For my purposes, I created a profile that looked like this:

TestMode = 0
TimeInterval = 1
*\convert.exe := PAIR0+PAIR1

This profile sets any convert.exe process to use the first two CPU core pairs (CPU0, CPU1, CPU2, and CPU3), polling every second. TestMode is a toggle that allows you to see if your profile is working without actually setting affinities.

Hope someone finds this useful!

Solution 4

I'm new here and first time posted on this forum but anyway I've created this chart which makes it much easier to understand, just enter the hex value Y in the command line to enable the number of CPU threads. Enjoy!

CPU - HEX  - BINARY
00 -- 1 ---- 0001
01 -- 3 ---- 0011
02 -- 7 ---- 0111
03 -- F ---- 1111
04 -- 1F --- 0001 1111
05 -- 3F --- 0011 1111
06 -- 7F --- 0111 1111
07 -- FF --- 1111 1111
08 -- 1FF -- 0001 1111 1111
09 -- 3FF -- 0011 1111 1111
10 -- 7FF -- 0111 1111 1111
11 -- FFF -- 1111 1111 1111
12 -- 1FFF - 0001 1111 1111 1111
13 -- 3FFF - 0011 1111 1111 1111
14 -- 7FFF - 0111 1111 1111 1111
15 -- FFFF - 1111 1111 1111 1111

%ComSpec% /c start /affinity Y game.exe
Share:
39,810

Related videos on Youtube

yuritsuki
Author by

yuritsuki

The 💰 intent 💰 is 💰 to 💰 provide 💰 players 💰 with 💰 a 💰 sense 💰 of 💰 pride 💰 and 💰 accomplishment 💰 for 💰 unlocking 💰 different 💰 Arqade benefits. 💰 As 💰 for 💰 cost, 💰 we 💰 selected 💰 initial 💰 values 💰 based 💰 upon 💰 data 💰 from 💰 the 💰 Open 💰 Beta 💰 and 💰 other 💰 adjustments 💰 made 💰 to 💰 reputation 💰 rewards 💰 before 💰 launch. 💰 Among 💰 other 💰 things, 💰 we're 💰 looking 💰 at 💰 average 💰 per-user 💰 reputation 💰 earn 💰 rates 💰 on 💰 a 💰 daily 💰 basis, 💰 and 💰 we'll 💰 be 💰 making 💰 constant 💰 adjustments 💰 to 💰 ensure 💰 that 💰 users 💰 have 💰 challenges 💰 that 💰 are 💰 compelling, 💰 rewarding, 💰 and 💰 of 💰 course 💰 attainable 💰 via 💰 gameplay. We 💰 appreciate 💰 the 💰 candid 💰 feedback, 💰 and 💰 the 💰 passion 💰 the 💰 community 💰 has 💰 put 💰 forth 💰 around 💰 the 💰 current 💰 topics 💰 here 💰 on 💰 Reddit, 💰 our 💰 forums 💰 and 💰 across 💰 numerous 💰 social 💰 media 💰 outlets. Our 💰 team 💰 will 💰 continue 💰 to 💰 make 💰 changes 💰 and 💰 monitor 💰 community 💰 feedback 💰 and 💰 update 💰 everyone 💰 as 💰 soon 💰 and 💰 as 💰 often 💰 as 💰 we 💰 can. 💰 💰

Updated on September 18, 2022

Comments

  • yuritsuki
    yuritsuki almost 2 years

    I have a game that has issues with CPU usage, so one of the fixes is to disable one core out of a quad core cpu. Since everytime I launch the game I have to manually go into the Task Manager and manually input the affinity, which sucks since the game is newly released yet prone to frequent crashes.

    Is there a NON SOFTWARE solution?

    I've looked up some solutions online and they seem to be geared towards Windows 7 only. Is there a solution for Windows 8.1 users like me?

    • Pacerier
      Pacerier about 9 years
      Please explain what do you mean by "manually input the affinity"?
    • yuritsuki
      yuritsuki about 9 years
      @Pacerier I have to manually change the affinity, since by default it picks all CPUs to work with.
    • CodesInChaos
      CodesInChaos about 9 years
      You could try setting the "Compatibility mode" to an old enough version of windows, which sets affinity to a single core. But I don't have win8 at hand to check if this still works.
    • Pacerier
      Pacerier about 9 years
      @cyberwebpoweruser, Did the answer below work for you?
  • Hasan Manzak
    Hasan Manzak about 9 years
    Oh, damn.. yes :) Corrected..
  • Nzall
    Nzall about 9 years
    @The_aLiEn question: If this process starts another process, does that second process inherit the affinity of the first process? I have the same problem with a game, but I need to change affinity on both the launcher and a 3rd party download manager that is started by the launcher for it to be solved.
  • Hasan Manzak
    Hasan Manzak about 9 years
    @NateKerkhofs it should inherit. Not just affinity, like all security descriptors, handles owned, etc.
  • Pacerier
    Pacerier about 9 years
    "non-software" means cmd.
  • ihavenokia
    ihavenokia almost 7 years
    thanks a lot! this helped me to change the affinity in my C# program!