JSI Tip 3542. How can I permanently set the processor affinity for an application?
April 2, 2001
In tip 0209, I describe how you can set the processor affinity on a running application.
In tip 2191, I described how bind devices to processors, to improve performance by more effectively using the processor's cache.
You can permanently set processor affinity for a non-operating system executable, on both Windows 2000 and Windows NT 4.0, by using the Imagecfg.exe tool from the supportdebugi386 folder of a Windows NT 4.0 CD-ROM, or the Imagecfg.exe tool from the Windows 2000 Server Resource Kit Supplement One.
NOTE: Do NOT use imagecfg on any kernel operating system files.
To permanently set the processor affinity for your 32-bit executable, open a CMD prompt and type:
imagecfg -a 0xn Pathyourprogram.exe
where 0xn is the affinity mask. The mask constrains your application to a specific CPU, from 0 - 31, where:
CPU MASK 0 0x1 1 0x2 2 0x4 3 0x8 4 0x10 5 0x20 6 0x40 7 0x80 8 0x100 etc
To set the affinity for "c:utilCountry Codes.exe" to processor 1, I typed:
imagecfg -a 0x2 "c:utilCountry Codes.exe"
and received the following response:
c:utilCountry Codes.exe contains no configuration informationc:utilCountry Codes.exe contains a Subsystem Version of 4.0c:utilCountry Codes.exe updated with the following configuration information: Process Affinity Mask: 00000002
When I launch Country Codes.exe, its' affinity is set to CPU 1.
About the Author
You May Also Like