[SOLVED] How to limit a program to a set amount of cores

Dec 14, 2018
8
0
10
so I want to limit discord to only allow it to use one core because it only needs that because if I have it on all cores it makes my games unplayable with like 40fps and cs with 40fps is not the way to go, so I only have it to one core and it only does like -(5-10)fps. Now I manually change it in the task manager in the thingy so can I have it automatically to one core so I don't need to do it every time I restart my pc? windows 10 btw if that makes a difference
 
Solution
for me, it's just discord_affinity.bat with above two lines.
Closing the box closing discord is likely due to discord then being said batch file's subprocess.

It works for me if I have it starting same way as discords own desktop shortcut does:
Code:
C:\Users\username\AppData\Local\Discord\Update.exe --processStart Discord.exe
powershell "Start-Sleep -s 15"
Powershell "ForEach($PROCESS in GET-PROCESS discord) { $PROCESS.ProcessorAffinity=1}"

and said batch file could be put in start menu's start-up folder, which is really in here:
C:\Users\username\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
Do not restart your PC.
Use sleep to ram instead.
That will put your pc and monitor into a low power state not much different from a complete power off.
The added benefit is that sleep or wake will be much faster.

I suppose you could write a start up script to change task properties as you wish.
 
Alternately, Google.
https://stackoverflow.com/questions/19187241/change-affinity-of-process-with-windows-script
Code:
Powershell "ForEach($PROCESS in GET-PROCESS processname) { $PROCESS.ProcessorAffinity=255}"

Just be sure to like... put said script in startup folder or somewhere, where it runs after discord has finished loading.
Also change process name to discord
Also look in provided source link if you want to use specific core (255 is all, 1 is core0, it's in binary)
 
like with all batch files, adding multiple lines is fine.
Code:
powershell "Start-Sleep -s 15"
Powershell "ForEach($PROCESS in GET-PROCESS discord) { $PROCESS.ProcessorAffinity=1}"

if you make your batch file content like that and put it in start-up folder or such, it'll wait 15 seconds in which time discord should have had time to autorun and then set the processor affinity. (you can use shorter time too, your choice)
if you don't have discord on autorun, you could just add path to run discord before that start-sleep line.

Also remember that the affinity numbers are in binary so 1 is core0, 2 is core2, 4 is core3 8 is core4, 16 is core5, 32 is core6, 64 is core7, 128 is core8
and if you want it to use more than one, you could put it on core 4 and 5 by having number be their sum, so 48
leaving cores 0 to 3 "free" Your choice of course.
 
Dec 14, 2018
8
0
10
I got it working the other way with it starting discord and that because I still have no idea in which folder i should put it in but what is the command for it to close command prompt/the code afterwards because it stays open and I don't remember that command anymore
 
for me, it's just discord_affinity.bat with above two lines.
Closing the box closing discord is likely due to discord then being said batch file's subprocess.

It works for me if I have it starting same way as discords own desktop shortcut does:
Code:
C:\Users\username\AppData\Local\Discord\Update.exe --processStart Discord.exe
powershell "Start-Sleep -s 15"
Powershell "ForEach($PROCESS in GET-PROCESS discord) { $PROCESS.ProcessorAffinity=1}"

and said batch file could be put in start menu's start-up folder, which is really in here:
C:\Users\username\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
 
Solution

TRENDING THREADS