How to programmatically set the processor affinity of an application

One of the user I support runs an older CAD application that doesn’t work properly on computers using a dual core processor. It creates ghosting artifacts when he draws and eventually crashes the application. The trick is to limit the application’s process to only one processor (or one core). To do it manually:

  1. Launch the application
  2. Locate the application’s process in the Task Manager (type taskmgr from the Run command or press Ctrl+Alt+Delete)
  3. Right-click on the process and select Set Affinity
  4. Uncheck all the selected CPUs except one.

It works well, but it needs to be done every time the application is launched.

To do it automatically, I downloaded a free command line utility from a company called Beyond Logic: process.exe. To have a process named ExampleAppProcess.exe use only CPU 1, type:

process -a ExampleAppProcess.exe 01

So, I copied process.exe in a folder and added the path to this folder to the PATH environment variable. Then, I opened Notepad and typed:

cd c:\Program Files\ExampleAppFolder
start ExampleApp.exe
process -a ExampleAppProcess.exe 01

I saved this file as Affinity.cmd and added a shortcut to it on the Desktop. I changed the name and the icon of the shortcut to match the one used by the original application, and then deleted the original shortcut.

Now my user doesn’t have to do anything special: He double-clicks on what appears the be the same shortcut as before, but now his application works.

4 responses to “How to programmatically set the processor affinity of an application

  1. Very nice works perfectly! Thanks

  2. you dont’s have to add paths in your enviromentals

    I’m using process.exe to set affinity for a game.
    All I did was put the process.exe in the same folder as the game exe file, created a bat file with the following lines:

    start UnrealTournament.exe
    process -a UnrealTournament.exe 01

    Then I just created a shortcut to the bat file and it is work without screwing with the enviromentals.

    works for me on vista 64 bit

    • The benefit of adding the path to the folder containing process.exe to the PATH environment variable is that I don’t have to remember where process.exe is located on my hard drive, it’s always available from anywhere at the command prompt.
      Also, some antivirus software remove process.exe. That’s why I wrote another article here where I use the Microsoft Application Compatibility Toolkit to set the processor affinity.

  3. Is there any option to set the core affinity to an application(written in Java) during runtime?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s