How to set processor affinity on an executable in Windows XP?
Asked Answered
M

8

10

I have a quad core system with third party application that once in a while spins several processes (always the same executable but several instances of it) and takes 100% of CPU time. I also have a couple of web services running on the same box (IIS and third party).

The problem with the all cores being busy is that it makes this third party web server to timeout (IIS works fine though, just slower than usual). I have no control over third party web server, it's a part of the bigger product and has to be operational. So, I tried to play with processor affinity (via SysInternals Process Explorer) and limit those pesky processes to 3 cores out of 4 and dedicate the 4th core to the third party web server, and it seems to work quite well.

The problem is that it only sets affinity on the running process and not on executable level, so after those processes finish and later respawn as a new processes it's all the same again - they take all 4 cores. So, I've googled about this ImageCfg.exe utility from Microsoft but I can't find it on Microsoft webside for download and I see that some people tried it and now complain that it doesn't really work.

Is there a way to stick the affinity to the executable?

Monad answered 9/3, 2009 at 21:10 Comment(2)
Your first call should be to the publisher of the software in question. Ask them how to limit the thread usage.Biserrate
However, the problem still interesting because the software may not have that feature. And there is certainly other software out there that doesn't...it would be annoying to have to call the vendor every time.Amphithecium
I
5

One feature of Process Lasso is to set the affinity of a process whenever that process is launched.

Imagery answered 9/3, 2009 at 21:14 Comment(0)
B
6

http://waynes-world-it.blogspot.com/2009/06/processor-affinity-on-windows-server.html

PowerShell

Use PowerShell to set the processor affinity for one or more running processes. There’s an example script below, setting the processor mask of calc.exe to the first 4 processors. I like this method because the script is simple, it would be easy to schedule, works on x86 and x64, supports multiple processes of the same name and at least partly because it highlights just how easy administration with PowerShell is.

Note that if you use factorial of a large number with calc.exe (n!) you’ll generate100% CPU which can be useful for testing. The mask below is 0xf = 1111 – a mask allowing use of only the first four processors:

$calcSet = Get-Process -ProcessName "calc"
foreach ($calc in $calcSet) {$calc.ProcessorAffinity=0xF}
Bonn answered 23/1, 2010 at 11:24 Comment(0)
I
5

One feature of Process Lasso is to set the affinity of a process whenever that process is launched.

Imagery answered 9/3, 2009 at 21:14 Comment(0)
O
4

You may want to look at the /AFFINITY parameter to start.

From the help:

AFFINITY    The new application will have the specified processor
            affinity mask, expressed as a hexadecimal number.

As processor affinity on Windows is a bitmask you may need some experimentation but I'd assume 1 being the first core, therefore 7 being the first three cores and F being all four. Or 8 for only the fourth.

You can then replace scheduled tasks or shortcuts with a call to start with the appropriate parameters.

Oraleeoralia answered 9/3, 2009 at 21:15 Comment(1)
Windows XP does not have the /affinity option.Proportionable
O
4

The ImageCfg.exe utility does work. I just used it to solve a company issue today. It is available from http://www.robpol86.com/pages/imagecfg.php

Imagecfg -a 0x3 xxx.exe

limits the .exe to CPU0 and CPU1, for example.

Orpah answered 12/6, 2009 at 20:42 Comment(0)
S
3

Use SetProcessAffinityMask(). And beware, Processor Affinity is inherited!

You'll need to use ImageFileExecutionOptions, specifically the "Debugger" option, and write your own small executable that calls SetProcessAffinityMask() on itself, and then spawns a new process, which is the one you want to set affinity for. Set that as the debugger, and you're done.

Sinh answered 9/3, 2009 at 21:15 Comment(1)
Really read the documentation on this one. You can easily shoot yourself in the foot with this; lots of gotchas.Sinh
H
3

You can use the single-proc affinity application shim to force one processor on the executable level, which will force the process onto one core.

This article, http://msdn.microsoft.com/en-us/library/bb173458.aspx, has a paragraph on enabling the shim towards the bottom.

Heshum answered 9/3, 2009 at 21:16 Comment(0)
S
1

Clearly this thread is outdated but im adding a comment anyway just in case anyone googles on this subject (as I did)

You could try setting the priority of the process so that even if it decides to use 100% of the CPU, something that is higher priority can take over when it needs to do so.

Doing this automatically (rather than having to play in the task manager) is something I asked about a while ago.

The start command can be used to set startup priority of a process.

Eg. start "my path\my process" /LOW for low priority.

Allowed priority switches LOW, NORMAL, HIGH, REALTIME, ABOVENORMAL, BELOWNORMAL

Could be called from a batchfile for example.

Southwesterly answered 14/9, 2012 at 17:58 Comment(1)
The question is about processor affinity, not process priority.Borehole
S
0

You could try setting the priority of the process so that even if it decides to use 100% of the CPU, something that is higher priority can take over when it needs to do so.

Doing this automatically (rather than having to play in the task manager) is something I asked about a while ago.

Sat answered 9/3, 2009 at 21:28 Comment(1)
The question is about processor affinity, not process priority.Borehole

© 2022 - 2024 — McMap. All rights reserved.