$PSTAT


General Forms:
  1. $PSTAT = alpha_expression
  2. alpha_receiver = $PSTAT [(numeric_expression)]

The $PSTAT statement is used to return status information for the specified partition. The first 8 bytes of $PSTAT may be changed with the first form.

Specifying no numeric expression for the second form of $PSTAT is the same as entering STR($PSTAT(#PART),,8).

Bytes used by $PSTAT
ByteDescription
1-8User specified status as set by the $PSTAT statement.
9Always 'K' for KCML.
10KCML release, HEX(30) for release 3.0, HEX(31) for release 3.1, HEX(32) for release 3.2 etc.
11Not used, always HEX(30).
12-13Partition size, current value of the SPACEK environment variable or HEX(9999) if not set.
14Programmability, 'P' if programmable (the default), ' ' if NOPROG environment variable is set.
15BCD terminal number, Always BCD HEX(99) for terminal 99 and above. See bytes 41-42 for true terminal number.
16Terminal status `A' if attached, 'D' if detached, 'W' if waiting to attach, 'F' if a suspended $RELEASE parent.
17-24Global name, all HEX(00) if no DEFFN @PART is executed.
25ERR function value, numeric code from last error whether trapped or not, else HEX(00). The subscript error code is stored in byte 49.
26BCD text partition number. The partition number of the text currently being executed. Always BCD, HEX(99) for partition 99 and above. See bytes 43-44 for true text partition. For KCML 6.0+ this is always set to #PART.
27BCD global partition number of the text currently selected in a SELECT @PART. Always BCD, HEX(99) for partition 99 and above. See bytes 45-46 for the true global partition number.
28BCD DATA partition number. Partition number containing the current RESTORE pointer. This will only be different from #PART if a RESTORE was executed in global text. Always BCD, HEX(99) for partition 99 and above. See bytes 47-48 for the true DATA partition number.
29DEVice awaited:
HEX(00) while executing - the partition will not respond to the PANIC CONTINUE or snoop signals.
HEX(01) if awaiting a keystroke.
HEX(FF) if blocked on $OPEN of a native file.
HEX(FD) if waiting on $IF or 'KCML_poll().
HEX(FC) if executing a SHELL statement.
HEX(FB) if executing a $BREAK statement.
HEX(FA) if waiting for a request when acting as a SOAP server.
Any other value should be interpreted as a device address from $DEVICE.
30-36User's login name. Truncated if longer than 7 bytes. Full usernames are displayed by the WebServer .
37-40Process id, four byte binary.
41-42#TERM in binary (supersedes byte 15).
43-44Executing partition in binary (supersedes byte 26). For KCML 6.0+ this is always set to #PART.
45-46Selected global partition in binary (supersedes byte 27).
47-48DATA partition in binary (supersedes byte 28).
49The subscript code for the last error (See byte 25.)
50-68Reserved
69-72IP address of WDW clients. For generic code use bytes 49-52 of $MACHINE.
73-74dynamic heap size in Kb. Only accurate upto 64Mb. For larger heap sizes use the PSTAT_HeapSize2 field of the KCML_PSTAT build in DEFRECORD
75client category,
'T' licensed for text only
'F' licenced for forms
'N' not applicable
'G' memory mapped global pseudo partition
'B' batch program, executed with the -p switch
'W' SOAP server that is using a [SOAP] licence
76-91Client computer name, if supplied by client program (null terminated string)
92Reserved
93-96$TIME format timestamp of last keyboard activity or, for a SOAP server, the last request. This value is not set for background partitions.
97-104Reserved
105-110*Client PC's MAC/Ethernet card address, 6-byte binary value
111-128Reserved
* MAC address on NT versions is between bytes 109 and 114

$PSTAT as a record

From version 06.20, KCML defines a KCML_PSTAT built in DEFRECORD that can be used to access the fields in $PSTAT e.g.

pid = FLD($PSTAT(#PART).PSTAT_ProcessId)

Compatibility notes

The extra fields from byte 50 onwards were introduced with KCML 6.0. Because of support for memory mapped globals and for libraries KCML 6.0+ no longer tracks the executing partition in bytes 43 and 44. If a SELECT@PART for a process global is in effect then bytes 45-46 will be set to the global's partition number but if the SELECT @PART referred to a memory mapped global then this field will be set to #PART. Similarly the DATA partition will only be set for a process global. These fields should be considered obsolete and should not be used.

The size of $PSTAT was increased to 128 bytes with build 9351 of KCML 6.0+.

KCML 6.20.73 & 7.05 allow the size of a partition to be increased the existance of /etc/kcml/pstat_X. The width of a partition is 2X, so for /etc/kcml/pstat_8, the width of partition is 28 = 256 bytes.
This value is also stored in byte 64 of $MACHINE.

The userid field was originally limited to the first 7 characters. From KCML 6.00 onward 16 character names were recorded but only the first 7 were available using the $PSTAT() function. When the DEFRECORD describing $PSTAT was introduced with KCML 6.40 then whole 16 characters were made available to the application.

DIM ps$_KCML_PSTAT DIM username$16 ps$ = $PSTAT(#PART) username$ = FLD(ps$.PSTAT_UserId$)

Syntax examples:

$PSTAT = user_message$
partition$ = $PSTAT
pt$ = STR($PSTAT,,3)

See also:

Configuring $PSTAT, $SYSTEMID, $KCML_PSTAT_SIZE, bkstat, Web Administration Tool, Internal structures