Sybase Business Intelligence Solutions - Database Management, Data Warehousing Software, Mobile Enterprise Applications and Messaging
Sybase Brand Color Bar

Search for    in all of
view all search results right arrow
Support > Technical Documents > Document Types > Technote > Binding a PowerBuilder Process to a CPU on Windows...

Binding a PowerBuilder Process to a CPU on Windows NT or Sun Solaris
RSS Feed


An application that is multi-threaded or an application that creates threads may have a contention problem on a multi-processor machine. The threads may actually be running at the same time on different processors. By binding a process to a cpu, no two threads are running at the same time and are not interfering with one another. Your application will run as if on a single-processor machine.

Binding on NT

You can bind a process to a cpu either from the Task Manager, using Win32 calls or permanently setting the processor affinity for an application executable.
(You need NT Administrator privileges to bind a process on NT.)

Binding from the Task Manager

1. Select the "Processes" tab in Task Manager.
2. Right mouse click on the process you want to bind and select "Set Affinity".
3. Select the cpu you want your application to run in.

Task Manager

Binding Using Win32 Calls

Use the SetProcessAffinityMask() function to bind a particular application to a cpu. The function is in the kernel32.dll. The first parameter is a handle to a process. Use the GetCurrentProcess to get the handle. The second parameter describes which processors the process should run on.

Declare the functions as follows:

function ulong GetCurrentProcess() library "kernel32.dll"
function boolean SetProcessAffinityMask(ulong hnd, ulong lpProcessAffinityMask) library "kernel32.dll"

Ulong lul_process,lul_lpProcessAffinityMask
Boolean b_result
integer ai_processor

// 0123 – As they appear in Task Manager (CPU 0, CPU 1, CPU 2, CPU 3)
ai_processor = 2

CHOOSE CASE ai_processor
lul_lpProcessAffinityMask = 1
lul_lpProcessAffinityMask = 2
lul_lpProcessAffinityMask = 4
lul_lpProcessAffinityMask = 8
Return FALSE

lul_process = GetCurrentProcess( )
b_result = SetProcessAffinityMask(lul_process, lul_lpProcessAffinityMask )

Permanently Setting the Processor Affinity for an Application Executable

On Windows NT, Windows 2000 or Windows XP, you can permanently set the processor affinity for an application executable by
using the imagecfg.exe tool.  This tool is located in the \support\debug\i386 folder on a Windows NT cdrom and from the Windows 2000 or Windows XP Server Resource Kit Supplement.  Open a DOS prompt and enter in the following:

imagecfg -a 0xn c:\program files\sybase\Jaguar CTS\bin\jagsrv.exe

where 0xn is the affinity mask and maps to a cpu as follows:
CPU         Mask
0                0x1
1                0x2
2                0x4
3                0x8
4                0x10
5                0x20

Binding on Solaris

You can bind a process to a cpu at the command line or using a shell script.

Binding at the command line

1. Use psrinfo to find the processor id # you want to bind to
2. pbind –b <processor id #> <pid>

Binding using a shell script

/export/home/mydir/testapp.exe &
/usr/sbin/pbind –b 1 $!


Last Revised: Mar 19, 2003
Part Number: 1010600
Product: PowerBuilder
Business or Technical: Technical
Content Id: 1010600
Infotype: Technote

© Copyright 2014, Sybase Inc. - v 7.6 Home / Contact Us / Help / Jobs / Legal / Privacy / Code of Ethics