- Setting Process Priority
- Setting Affinity
- Windows System Resource Manager
- Conclusions
Setting Affinity
By default, the Windows operating systems set processes to run on all available processors. If you have multiple processors or one or more dual-core processors in your system, you can control the processor(s) on which an application runs. On the Process tab of the Task Manager, right-click the desired process and select the Set Affinity option to open a dialog box like the one shown in Figure 3.
Figure 3 The Processor Affinity dialog box allows you to specify on which CPUs a process can be run.
Although you can use the Processor Affinity dialog box to control the CPUs on which applications run, many applications are also multiprocessor-aware. For example, Microsoft SQL Server 2000 and later versions allow you to configure processor priority within the application (see the Microsoft SQL Server 2000 Analysis Services Operations Guide for more information).
Using the RunFirst Command-Line Tool
If you have an application that’s not multiprocessor-aware, it may fail to run properly on a multiprocessor system. If that happens, you can use a free utility called RunFirst, which is a command-line tool that lets you start an application on the first processor of a multiprocessor system. The application does the same thing that you can do by using the Task Manager’s Set Affinity command, but because RunFirst is an executable file, you can run it from a batch file.
For example, assume that I have an application that I’ve noticed stops responding on my multiprocessor system, but runs well on my single-processor systems. Let’s say that the application is named OldApp.exe and is located in the C:\Apps\OldApps folder.
The RunFirst.exe application is located in the C:\Apps\RunFirst folder. I could create a batch file or even a Windows shortcut with this command:
C:\Software\RunFirst\RunFirst.exe C:\Software\OldApps\OldApp.exe
When that batch file or shortcut runs, OldApp.exe starts on the first processor in the system only. You can verify that it’s working properly by opening the Task Manager, right-clicking the OldApp.exe process, and selecting Set Affinity. In the Processor Affinity dialog box, you’ll see that OldApp.exe has a checkmark for only the first processor (see Figure 4).
Figure 4 OldApp.exe running on CPU 0 only.
Using the ImageCFG Utility
Another free application that you can use to specify the processor on which an application is allowed to run is ImageCFG. Unlike RunFirst, ImageCFG allows you to select the process on which your application will run. Continuing with OldApp.exe from the previous example, let’s assume that I want to run OldApp.exe on the second processor. I could run the following command from a command prompt:
ImageCFG 0x2 C:\Software\OldApps\OldApp.exe
This would create an affinity mask for the OldApp.exe application that would set it to run on the second processor only. The processor numbering scheme is simple: 0x1 refers to the first processor; 0x2 the second processor; 0x3 the third, and so on.
In addition to being able to target a specific processor, ImageCFG doesn’t require a batch file or shortcut. You simply run the utility once, and whenever you launch the application in the future, it’s now set to run on the processor you specified.