Changing the Process Priority for LabVIEW in Windows

Publish Date: Nov 16, 2010 | 8 Ratings | 4.38 out of 5 | Print | 1 Customer Review | Submit your review

Table of Contents

  1. Background Information
  2. Method 1: Manually Setting the Priority
  3. Method 2: Using Shortcut Commands
  4. Method 3: Programmatic access through kernel32.dll
  5. Related Links

1. Background Information

The effects of changing the priority of LabVIEW are untested and unknown.  may result in unexpected behavior and is not recommended under normal circumstances. However, if needed, listed are three methods to change the priority of LabVIEW for Windows. Methods 1 and 2 are not permanent, and the priority reverts back to the default when the process ends. Method 3 is permanent, and it is recommended that you manually return the process to its default priority when the program ends. Within each method, you can set the priority to one of the following six classes:

  • Low (or Idle) - Specifies that the threads of this process run only when the system is idle. The threads of this process are preempted by the threads of any other process running in a higher class. 
  • Below Normal - Specifies that the process has priority above Low but below Normal.
  • Normal - (Default) Specifies that the process has no special scheduling needs.
  • Above Normal - Specifies that the process has priority above Normal but below High. 
  • High - Specifies that the process performs time-critical tasks that must be executed immediately. Use care when specifying a process as High priority because these threads can use nearly all available processor time.
  • Realtime - Specifies the highest possible priority. Realtime process priority threads preempt the threads of all other processes. This can cause unexpected results and system crashes and is not recommended.

Note: Under Win32 based operating systems, a priority is not a guarantee for CPU time allocation but a method to go faster than other processes or threads with lower priorities.

Back to Top

2. Method 1: Manually Setting the Priority

Complete the following steps to set the priority manually.

1. Press <Ctrl-Alt-Del> to open the Task Manager.
2. Select the Processes page.
3. Right-click the LabVIEW process and select Set Priority»Priority Class, where Priority Class is the desired class setting. 

Back to Top

3. Method 2: Using Shortcut Commands

Complete the following steps to create a shortcut that will set the priority upon startup.

  1. Open My Computer.
  2. Navigate to the LabVIEW.exe file located at C:\Program Files\National Instruments\LabVIEW
  3. Right-click on LabVIEW.exe and select Create Shortcut.
  4. Right-click the shortcut and select Properties.
  5. Clear the target field, and replace it with cmd /c start /high labview.exe
  6. Run the shortcut to start LabVIEW in High priority mode.

Note:  You can replace “high” in the target field with any of the five other class tags.

Back to Top

4. Method 3: Programmatic access through kernel32.dll

Complete the following steps to programmatically set the priority of a process. This method makes calls to kernel32.dll using two Call Library Function Nodes. 

LabVIEW can be set to run as one of the following six priorities which are listed with their respective identifiers:

IDLE: IDLE_PRIORITY_CLASS
BELOW NORMAL: BELOW_NORMAL_PRIORITY_CLASS
NORMAL: NORMAL_PRIORITY_CLASS
ABOVE NORMAL: ABOVE_NORMAL_PRIORITY_CLASS
HIGH PRIORITY: HIGH_PRIORITY_CLASS
REAL TIME: REALTIME_PRIORITY_CLASS


1.  In LabVIEW, add a Call Library Function Node to the block diagram.
2.  Right-click the node and select Configure.
3.  Enter C:\Windows\System32\kernel32.dll for the Library Path
4.  Select GetCurrentProcess as the Function Name and stdcall(WINAPI) as the Calling Convention.
5.  Set the Parameter to have the Function Prototype read unsigned long GetCurrentProcess(void);
6.  Add a second Call Library Function Node to the block diagram.
7.  Enter C:\Windows\System 32\kernel32.dll as the Library Path.  
8.  Select SetPriorityClass as the Function Name and stdcall(WINAPI) as the Calling Convention.
9.  Set the parameters to have the Function Prototype read unsigned long SetPriorityClass(unsigned long handle, unsigned long priority);

Wire the output parameter of GetCurrent Process to the handle input of SetPriorityClass. Wire a constant to the priority input of SetPriorityClass. The constant will be the hexadecimal (hex) value that corresponds to the desired priority level. In the winbase.h file (included in the Win32 SDK from Microsoft), you can find the statements that define the priority levels which are also listed below.

#define IDLE_PRIORITY_CLASS 0x00000040
#define BELOW_NORMAL_PRIORITY_CLASS 0x00004000
#define NORMAL_PRIORITY_CLASS 0x00000020
#define ABOVE_NORMAL_PRIORITY_CLASS 0x00008000
#define HIGH_PRIORITY_CLASS 0x00000080
#define REALTIME_PRIORITY_CLASS 0x00000100

With these values, you can assign the priority of the thread. For example, to set the priority of your process to IDLE, you can wire in a constant with the hex value 40 to the priority input of the SetPriorityClass function.

To experiment with this method in LabVIEW 8.0 or later, open and run the example VI attached below. As you run the example, open Windows Task Manager to view the changing priority status of LabVIEW while you change the status in the VI.  

Note: If you set the priority using this method or example VI, it is permanent and remains set until you set it to a new value. It is recommended that you return the priority to its default value when you are finished.

Back to Top

5. Related Links

MSDN: SetPriorityClass Function

MSDN: GetCurrentProcess Function

Back to Top

Customer Reviews
1 Review | Submit your review

There is a bug in the example  - Jul 31, 2010

The priority values are given as hexadecimal terms (hence the 0x00...). In the example program the constant used to specify the process priority is displaying the value as decimal and so will set the priority to the wrong value. Changing the display format to hexadecimal and changing the value will fix this.

Bookmark & Share


Downloads


Ratings

Rate this document

Answered Your Question?
Yes No

Submit