Ever since the introduction of the multitasking processor, operating systems have been able to handle running multiple programs at once using the new task switching and segmentation features provided by the CPU. These new technologies made it possible for operating systems such as Windows to be created. Even though PCs today are able to multitask, they still really can do only one thing at a time. In order for the operating system to support running dozens of applications at once, it has to slice up all the available processing time and give each application a turn. Although this is starting to change now with the introduction of multi-core processors, each core can still do only one thing at a time.
Operating systems use a variety of techniques to determine which application will get the next available slot to use the CPU. One of the factors that determine this for Windows Vista is the priority level at which the application is running.
Every application that runs on your computer has a priority level attached to its runtime record. By default, the operating system starts each application at normal priority, which is right in the middle of the priority spectrum. Applications can run and be assigned six different priority levels, ranked from highest to lowest: Realtime, High, Above Normal, Normal, Below Normal, and Low. Because the CPU can do only one thing at a time, the different priority levels allow the operating system to decide which application will get the next CPU burst. If an application is running at the High or Above Normal priority level, it will get more CPU time than an application running at the Normal level.
As you can see, the priority you give an application can affect how fast the program runs.
Windows Task Manager is something that everyone experiences when they have problems with a frozen program. However, you learned that Task Manager is a very useful utility in Chapter 8. Another use of Task Manager is to change the priority at which an application is running. This capability can be very useful when you have a lot of programs running on your computer.
Setting any application to Realtime can be dangerous because doing so allows the application to hog all the CPU time. Trying to exit a program that is running at this high priority is next to impossible if for some reason it crashes or is stuck in a loop. It takes a very long time to just load Task Manager to end the application because the program is hogging all the CPU time.
If you have an application that has a high need for CPU operations such as rendering a video clip or a game, you can adjust the priority of the application by following these steps:
To load Task Manager, click the Start button, type taskmgr in the Search box, and then press Enter. If you have User Account Control enabled, you will need to run Task Manager under an account that is a member of the Administrators group on your computer. Alternatively, you can type runas /u:Administrator taskmgr to start Task Manager in the Administrator permission level but while you are logged on.
After Task Manager loads, click the Processes tab.
Right-click the name of the process for which you would like to adjust the priority, select Set Priority, and then select the level, as shown in Figure 12-8. Your change is now complete.
Figure 12-8: Using Task Manager to adjust application priorities
If your computer has multiple processors or multiple cores, or supports hyperthreading, then you will notice an extra option, Set Affinity, when you right-click a process. This option enables you to specify on which CPU the application will run (or which virtual CPU, in the case of hyper-threading users).
Using Task Manager to change the priority levels is great. However, there is one downside. When an application on which you have altered the priority level is closed, the priority level it was running at will be lost. The next time that the program is started, the program will be running back at the default level. This downside can be a pain in the butt for some users; however, a cool trick will fix this problem, as discussed in the next section.
A wonderful command built into Windows Vista allows you to start any program and specify its priority. This cool utility is called the Start command. Using the Start command with priority flags followed by the executable enables you to start any program at a priority level of your choosing.
For the sake of demonstrating how to use the command, assume that the Calculator is set at high CPU priority. Follow these steps to set the command:
Open Notepad to type the command so that it can be turned into a batch script file. This can be done by starting Notepad from the Accessories item in the Start menu's All Program entry.
After Notepad opens, type start /high calc.exe. If you want to start the Calculator at a different priority, you can replace /high with /low, /normal, /realtime/, /abovenormal, or /belownormal.
After keying in the priority level, click the File menu bar item in Notepad and select Save As. Change the file Save As Type to All Files and type launchcalc.bat in the filename box. You can call the file anything you want, but make sure that it has the .bat file extension so that Windows knows to execute the commands in the file.
Specify a location on your hard drive to save it, such as your desktop, and click the Save button. You are now finished and can exit Notepad.
Now that you have created the batch command file, you are ready to start your new shortcut.
This tweak will work only if you run each batch file as an administrator or disable User Account Control. This is another tweak that is affected by User Account Control. Learn how to disable this in Chapter 14.
The same technique can be applied to any program on your computer. Instead of typing calc.exe at the end of the command, type the name of the executable of the program that you want to start.
Additionally, this command can be used on nonexecutable files such as documents. For example, you can type start /high mydocument.doc to start Microsoft Word in the High priority level with your document opened.
Another great utility, made by Uniblue, is called WinTasks Pro. This utility is like Windows Task Manager, but on steroids. It offers tons of new features that Windows Task Manager does not have, such as the ability to see individual CPU and memory graphs for each application, scripting capabilities that allow the user to set up triggers based on CPU and memory activity for each application, and most important, the ability to have preset profiles for application priority levels. In addition to these features, it has built-in information about quite a few commonly known processes to help users figure out each process that is listed because they are often not easily identified by the process name.
Having a profile for your open application priority levels enables you to automatically change the priority of several applications at the click of a button.
WinTasks 5 Professional can be downloaded from http://www.liutilities.com/products/trial/. Download a copy now and install it if you would like to follow along with these steps, which guide you through creating a profile of your priorities:
To start WinTasks, click the Start button and type Start WinTasks. The shortcut will appear at the top of the list. Right-click the shortcut and select Run as administrator.
After WinTasks loads, you will see a list of all the different processes running on your computer. You can adjust the priority at which each process is running by right-clicking on the process and then selecting either Increase or Decrease Priority. Go ahead and change the priorities of all the applications that you have running to what you would like them to be.
When you are satisfied with all your priority changes and are ready to create a profile of them, click the little key icon on the Presets toolbar, as shown in Figure 12-9. If you do not see the Presets toolbar, select View Toolbars Presets.
Figure 12-9: WinTasks Professional Presets save icon
Type a name to save the state of all the priorities as in the Save Preset window and press OK.
Next to the key icon that you pressed, you will notice the name showing up in the button to the right of it. Every time you press this button it will reset all the priorities to what you changed them to for this preset.
Repeat the previous steps, changing the priority levels for each application to a different value and then clicking on a different key icon to save the new preset again.
Now that you have multiple presets of application priority levels, you can easily switch between them by clicking the buttons.
The capability to create separate presets of priority levels for different applications allows you to optimize certain programs, depending on what you are doing. For example, you can create a profile for your processes when you want to play a game. To do that, you can decrease the priority of many of the system processes and applications running in the background so that a game running at normal or higher priority will have more CPU time.
Lower the priorities of all the other background applications, such as your instant messaging programs. This will allow your game to run faster because these other background applications will have a lower priority.