ProcessSerialNumber
Defines the unique identifier for an open process.
struct ProcessSerialNumber {
unsigned long highLongOfPSN;
unsigned long lowLongOfPSN;
};
typedef struct ProcessSerialNumber ProcessSerialNumber;
typedef ProcessSerialNumber * ProcessSerialNumberPtr;
Fields
highLongOfPSN
The high-order long integer of the process serial number.
lowLongOfPSN
The low-order long integer of the process serial number.
Discussion
All applications (defined as things which can appear in the Dock that are not documents and are launched by the Finder or Dock) on Mac OS X have a unique process serial number. This number is created when the application launches, and remains until the application quits. Other system services, like Apple events, use the ProcessSerialNumber structure to specify an application.
During launch, every application checks in with the Process Manager. Before this checkin, the application can not receive events or draw to the screen. Prior to Mac OS 10.2, this check in occurred before the applications's main function was entered. In Mac OS 10.2 and later, this check in does not occur until the first time the application calls a Process Manager function, or until it enters CFRunLoopRun for the main event loop. This allows tools and other executables which do not need to receive events to link against more of the higher level toolbox frameworks, but may cause a problem if the application expects to be able to retrieve events or use CoreGraphics services before this checkin has occurred. An application can force the connection to the Process Manager to be set up by calling any Process Manager routine, but the recommended way to do this is to call GetCurrentProcess to ask for the current application's PSN. Doing so initializes the connection to the Process Manager if it has not already been set up and check in the application with the system.
You should not make any assumptions about the meaning of the bits in a process serial number. To compare two process serial numbers, you should use the function SameProcess.
You can obtain a process serial number in one of the following ways:
Process serial numbers are returned by the functions LaunchApplication, GetCurrentProcess, and GetFrontProcess.
Some high-level events return process serial numbers.
If you want to specify a process using the Process Identification Constants, you must populate a process serial number structure, passing 0 in highLongOfPSN and the appropriate constant (such as kCurrentProcess) in lowLongOfPSN. For example, to bring the current process forward, you can use the following code:
ProcessSerialNumber psn = { 0, kCurrentProcess };
SetFrontProcess( &psn );