Important: The information in this document is obsolete and should not be used for new development.
Getting Information About Other Processes
You can call theGetNextProcess
,GetFrontProcess
, orGetCurrentProcess
functions to get the process serial number of a process. TheGetCurrentProcess
function returns the process serial number of the process currently executing, called the current process. This is the process whose A5 world is currently valid; this process can be in the background or foreground. TheGetFrontProcess
function returns the process serial number of the foreground process. For example, if your process is running in the background, you can useGetFrontProcess
to determine which process is in the foreground.The Process Manager maintains a list of all open processes. You can specify the process serial number of a process currently in the list and call
GetNextProcess
to get the process serial number of the next process in the list. The interpretation of the value
of a process serial number and of the order of the list of processes is internal to the Process Manager.When specifying a particular process, use only a process serial number returned by a high-level event or a Process Manager routine, or constants defined by the Process Manager. You can use these constants to specify special processes:
CONST kNoProcess = 0; {process doesn't exist} kSystemProcess = 1; {process belongs to OS} kCurrentProcess = 2; {the current process}In all Process Manager routines, the constantkNoProcess
refers to a process that doesn't exist, the constantkSystemProcess
refers to a process belonging to the Operating System, and the constantkCurrentProcess
refers to the current process.To begin enumerating a list of processes, call the
GetNextProcess
function and specify the constantkNoProcess
as the parameter. In response,GetNextProcess
returns the process serial number of the first process in the list. You can use the returned process serial number to get the process serial number of the next process in the list. When theGetNextProcess
function reaches the end of the list, it returns the constantkNoProcess
and the result codeprocNotFound
.You can also use a process serial number to specify a target application when your application sends a high-level event. See the chapter "Event Manager" in Inside Macintosh: Macintosh Toolbox Essentials for information on how to use a process serial number when your application sends a high-level event.
You can call the
GetProcessInformation
function to obtain information about any process, including your own. For example, for a specified process, you can find
The
- the application's name as it appears in the Application menu
- the type and signature of the application
- the number of bytes in the application partition
- the number of free bytes in the application heap
- the application that launched the application
GetProcessInformation
function returns information in a process information record, which is defined by theProcessInfoRec
data type.
TYPE ProcessInfoRec = RECORD processInfoLength: LongInt; {length of process info record} processName: StringPtr; {name of this process} processNumber: ProcessSerialNumber; {psn of this process} processType: LongInt; {file type of application file} processSignature: OSType; {signature of application file} processMode: LongInt; {'SIZE' resource flags} processLocation: Ptr; {address of partition} processSize: LongInt; {partition size} processFreeMem: LongInt; {free bytes in heap} processLauncher: ProcessSerialNumber; {process that launched this one} processLaunchDate: LongInt; {time when launched} processActiveTime: LongInt; {accumulated CPU time} processAppSpec: FSSpecPtr; {location of the file} END;You specify the values for three fields of the process information record:processInfoLength
,processName
, andprocessAppSpec
. You must either set theprocessName
andprocessAppSpec
fields toNIL
or set these fields to point to memory that you have allocated for them. TheGetProcessInformation
function returns information in all other fields of the process information record. See "Process Information Record" on page 2-16 for a complete description of the fields of this record.Listing 2-1 shows how you can use the
GetNextProcess
function with theGetProcessInformation
function to search the process list for a specific process.Listing 2-1 Searching for a specific process
FUNCTION FindAProcess (signature: OSType; VAR process: ProcessSerialNumber; VAR InfoRec: ProcessInfoRec; myFSSpecPtr: FSSpecPtr; myName: Str31): Boolean; BEGIN FindAProcess := FALSE; {assume FALSE} process.highLongOfPSN := 0; process.lowLongOfPSN := kNoProcess; {start at the beginning} InfoRec.processInfoLength := sizeof(ProcessInfoRec); InfoRec.processName := myName; InfoRec.processAppSpec := myFSSpecPtr; WHILE (GetNextProcess(process) = noErr) DO BEGIN IF GetProcessInformation(process, InfoRec) = noErr THEN BEGIN IF (InfoRec.processType = LongInt('APPL')) AND (InfoRec.processSignature = signature) THEN BEGIN {found the process} FindAProcess := TRUE; Exit(FindAProcess); END; END; END; {WHILE} END;The code in Listing 2-1 searches the process list for the application with the specified signature. For example, you might want to find a specific process so that you can send a high-level event to it.