Hello,
I have 8 logical processors, but my programs seem to love running only on the first. Is there a way to force an executable on Windows, execute on the processor we tell it to? If so, how does it work?
Thanks.
How can I force my program use this or this core?
-
- Posts: 2958
- Joined: Jun 02, 2015 16:24
Re: How can I force my program use this or this core?
Hi TT,
Found that :
the first trick is via task manager
https://www.howtogeek.com/121775/how-to ... cific-cpu/
The second one via line command
Maybe it could possible programatically. Not tested I don't know if it's for real processors or also logical ones.
Found that :
the first trick is via task manager
https://www.howtogeek.com/121775/how-to ... cific-cpu/
The second one via line command
Code: Select all
c:\windows\system32\cmd.exe /C start /affinity 1 notepad.exe
-
- Posts: 2958
- Joined: Jun 02, 2015 16:24
Re: How can I force my program use this or this core?
Thanks a lot for the quick answer. I will give this a try :)SARG wrote:Hi TT,
Found that :
the first trick is via task manager
https://www.howtogeek.com/121775/how-to ... cific-cpu/
The second one via line commandMaybe it could possible programatically.Code: Select all
c:\windows\system32\cmd.exe /C start /affinity 1 notepad.exe
Re: How can I force my program use this or this core?
j'aime bien ce genre de chose :-) I like this sort of stuff.Tourist Trap wrote: Thanks a lot for the quick answer. I will give this a try :)
For doing by program use SetProcessAffinityMask(ProcInfo.hProcess, dword(cpuset))
-
- Posts: 2958
- Joined: Jun 02, 2015 16:24
Re: How can I force my program use this or this core?
Alors je me permets poser une autre question ;)SARG wrote:j'aime bien ce genre de chose :-)
I'll have to test this one first, but I have in fact more questions in the same domain. Sometimes we have a child process that gets stuck, how can we kill a child without killing the parent? It rarely works in the task manager, when you kill a child everything is dropped with it.For doing by program use SetProcessAffinityMask(ProcInfo.hProcess, dword(cpuset))
Any idea about this?
Re: How can I force my program use this or this core?
Note that unnecessarily binding to a core can frustrate CPU's heat management, causing it to clock down. The scheduler rotates heavy CPU using processes across cores to move the source of heat around, heating it more evenly with a lower peak temperature.Tourist Trap wrote: I'll have to test this one first, but I have in fact more questions in the same domain. Sometimes we have a child process that gets stuck, how can we kill a child without killing the parent? It rarely works in the task manager, when you kill a child everything is dropped with it.
Any idea about this?
To let the child be independent, it has to be executed in a certain way. Sometimes the child itself also has to perform certain things (like closing handles from the parent). It is not so much as that you can choose how to kill it externally, the bond must be broken by the programs themselves.
This process is called "daemonization" on Unix. On Windows it is done by passing DETACHED_WINDOW to the createprocess instance (as a quick example I found https://codereview.stackexchange.com/qu ... ft-windows)
OR use shelleexecute to execute the program.
Re: How can I force my program use this or this core?
I don't know if there is a solution for all the cases. It should depend of how the parent and child are 'linked'.Tourist Trap wrote:I'll have to test this one first, but I have in fact more questions in the same domain. Sometimes we have a child process that gets stuck, how can we kill a child without killing the parent? It rarely works in the task manager, when you kill a child everything is dropped with it.
Any idea about this?
Post an example and I'll look for (later, busy by gas64) a way.
About setting affinity, as marcov said and also written in the text of the link it isn't a good thing to manage yourself what cpus are to be used.