This class allows manipulation and display of Cache processes running on the system.
An instance of the class can be opened by passing the PID (O/S process id)
to the %OpenId Method. The PID is in decimal form ($J) for all platforms.

NOTE: Previous versions of this class allowed you to call the %OpenId method
and pass in either a PID preceded by the letter "P", or a job number preceded
by the letter "J". This functionality has been removed from the %OpenId() method,
and moved to the new Open() method which supports this syntax.

Performance considerations:
When you use %OpenId() to examine a process, several mailbox messages will get sent to
the process to return ALL of the properties for the object. On systems with lots of processes
running, and you are collecting data for a lot of processes, this can cause a lot of overhead.
The call to each %OpenId() in this case may actually take several seconds to complete.
Most of a processes properties can be retrieved without the overhead of a mailbox message. See
the description of the individual properties below for which properties require a mailbox message
to be sent.
If you want to minimize overhead, you should use an SQL statement to select ONLY the data
which you want returned. For example, here is some code which loops through all the processes
on the system, and retrieves specific data for each process. Note that the properties which
are returned in this example are ones which do not require a mailbox messages to be sent to the
process being examined. Note that the %syPidtab.inc file needs to be included in your routine
in order for the following code to compile cleanly.

Security considerations:
Any process can open an instance to their own process by passing the value of $J to
the %OpenId() method:

s Process=##CLASS(%SYS.ProcessQuery).%OpenId($j)

If you wish to open another process, you must own the %Admin_Manage:Use
resource, or have read or write access to the CACHESYS database. To minimize overhead in
the %OpenId() method, having the %Admin_Manage:Use privilege is recommended.
This class has an SQL table called %SYS.ProcessQuery where you can execute an SQL
query to return process data. For example you could execute the following
queries:

Select * from %SYS.ProcessQuery - Return all information about all processes
Select * from %SYS.ProcessQuery where NameSpace = 'User" - Return all information about
all processes in the USER namespace.
Note that in order to run this from an unprivileged user, you may need to grant privileges
to that user on the table as follows:

GRANT SELECT ON %SYS.ProcessQuery TO _PUBLIC

Notes:
Replace _PUBLIC to a specific user or role name if you don't want everyone to have the privilege.
This is per-namespace. This needs to be executed in each namespace the table needs to be queried from.

DEFAULTCONCURRENCY is the default value for the concurrency formal argument
defined for %Open, %OpenId, %Delete and %DeleteId methods. It is not the default
value of the %Concurrency property of persistent classes. If the value of the actual
concurrency argument passed to any of the above methods is -1 then the formal argument value will
be set to the value of the DEFAULTCONCURRENCY parameter value defined for the class.

CSP Session ID of client connected to process.
CSP session ID of the client which initiated the connection.
It is passed down to the process as part of the initial connection message,
and used to manager the CSP session.

Executable name of the process on the client.
The name of the Executable or DLL on the client which initiated the connection.
It is passed down to the process as part of the initial connection message.
This property may be set by the end-user if they are managing their own connections.

IP Address of client connected to the process.
IP address of the client which initiated the connection.
It is passed down to the process as part of the initial connection message.
This property may be set by the end-user if they are managing their own connections.

Node Name of the client connected to the process.
Node name of the client which initiated the connection.
It is passed down to the process as part of the initial connection message.
This property may be set by the end-user if they are managing their own connections.

Current Source Line being executed.
Current line of source code which is being executed by the process. If "",
then the source code line is unavailable.
This property requires a mailbox message to be sent to the process being examined.
If the routine has been modified compared to the pcode being run then this will point to
the current routine source rather than the actual source of the code being executed.

In a transaction.
If 0, the process is not in a transaction.
If >0, the process has executed a tstart command, is in a transaction, and the value
is the offset in the journal file where the transaction has started.

Is a Ghost process.
The process has been killed at the O/S level, and has not yet been cleaned
up by the CLNDMN process. Until the process is cleaned, their may be outstanding
locks or resources which may be unavailable to other processes.
This property requires a mailbox message to be sent to the process being examined.

Job type.
Number which tells what type of process it is.
See the %syPidtab.inc include file for a definition of macros for these fields.
Only use the defined macros in %syPidtab when referencing these fields.
For example:

Number of Lines Executed.
Total number of lines which the process has executed.
NOTE: This property is deprecated, line counts are no longer available and this actually returns the CommandsExecuted.
It is left here for backwards compatibility, but should no longer be used.

Operating system username of process.
Username given to the process by the operating system when the process
is created. When displayed, it is truncated to 16 characters. Note that the real O/S
username is only returned when connecting to UNIX or VMS systems; For Windows, it
will return the O/S username for a console process, but for telnet it will return
the $USERNAME of the process. For client connections, it contains the O/S username
of the client. This field is truncated at 16 characters.

State.
Current state of the process as determined by the processes state bits.
The following are all the different states a process can be in. The process may
also have a number of different flags within these states which are appended to
the end of the state name:
LOCK - Executing a Lock command
OPEN - Opening a device
CLOS - Closing a device
USE - Using a device
READ - Read command
WRT - Write command
GET - Executing a $Get on a global
GSET - Setting a global
GKLL - Killing a global
GORD - $Order on a global
GQRY - $Query on a global
GDEF - $Data on a global
ZF - Executing a $ZF command
HANG - Executing a Hang command
JOB - Executing a Job command
EXAM - Executing a variable exam
BRD - Executing a broadcast
SUSP - Process is suspended
INCR - Executing a $Increment
BSET - Set $bitset
BGET - get $bitset
EVT - Waiting on event
RUN - Process is running

User defined information.
This is a user-defined property where the process can set any value into it up
to 16 bytes long. The data in it is viewable in JOBEXAM. Note that
the information can only be set into one's own process, not into
another user's process.

Retrieve a snapshot of the execution stack and variables for a process in the same format as JOBEXAM.

Parameters:
Pid - Process ID ($J) of the process to examine
GetVariables - Flag to specify that all variables and their values should be returned
Timeout - How long to wait for the process to respond to the request

Return Value:
On success, the method will return an index of the ^mtemp global (greater than zero).
If an error occurs a status code is returned.
Note that, like JOBEXAM, the request will time out if the process is not executing commands.

The data in the ^mtemp node can be displayed by calling Show^%STACK(index).
It is the responsibility of the caller to Kill ^mtemp(index) when finished with the data.

The data is returned in these nodes of the ^mtemp(index) global:
("*STACK") = the number of stack levels
("*STACK",0,"V",SpecialVar) = the values of special variables such as $S and $ZE
("*STACK",level,"L") = the text line for this level, as displayed by %STACK or JOBEXAM
("*STACK",level,"S") = the source line for this level, with a tilde inserted in front of the current command
("*STACK",level,"I") = the internal data for this level

If variables are requested:
("*LEVEL",level,variable) = the base level of a variable that is visible at this level
("*NAMES",variable,base,level) - this is the same information as *LEVEL in a different format
("*STACK",base,"V",variable) = the value of the variable at its base level

Available only for the current process, you can not query
another process. If a class method is passed on the command line
then 'Label' will be the method name and 'Routine' will be the
class name with a trailing '#' to identify it as a class.

This method returns the OSUsername of the process as returned by the operating system.
This method differs from the OSUsername property in that it is the actual username assigned to
the process by the operating system.

Return Value:
On success, the method will return a $LIST of devices that are currently open by the process.
The principal device is the first item in the list. The current device has an asterisk appended to the name.
If an error occurs an empty string is returned.

Returns the next process pid on the system.
This is like a $order function on processes running on the system, similar to the way
$ZJOB works. It differs from $zjob in one respect though. If the pid passed into
the function has halted before this call, we will still return the next pid on the
system. $zjob would return the first pid on the system in this case. Using $zjob in
this way with lots of processes starting and halting could lead to inaccurate results.
Flag=1 means pass in and return the internal decimal representation of a VMS pid ($zh(pid))

Open an instance to a process.
This method will open an instance to a process by passing either
a PID or Job number to the method. A Pid can either be directly passed in or
prefaced with a "P". A Job number can be passed in prefaced by a "J".
The following open an instance to a process with a pid = 2078:
s Process=##CLASS(%SYS.ProcessQuery).Open("P2078")
s Process=##CLASS(%SYS.ProcessQuery).Open("2078")

The following will open Job number 23

s Process=##CLASS(%SYS.ProcessQuery).Open("J23")

Parameters:
Id - Pid or Job number to open
Concurrency - Pass -1 or use default
sc (by ref)- Status of the Open
Return values:
On success, the method returns an object handle to the opened process.
On failure, the method returns a null string, and an error in sc.

Returns ALL properties for a process
This query performs a Select * on %SYS.ProcessQuery SQL query.
Note that this query uses a $v(-1,$j) mailbox message to
query processes. This causes a lot of overhead, but is necessary in
order to return all fields. Use the JOBEXAM, CONTROLPANEL, or SS
query for less overhead.
This query will change in future versions as field are added or removed.

Returns fields for the Management Portal display
Note that this query does not use a $v(-1,$j) mailbox message to
query processes. This avoids unecessary overhead.
This query may change in future versions.
Parameters:
JobNumber - Job number of where to start the query, default = 1 (first job)
Filter - Display processes which contain this filter in the line, "" means display all.
For example, if Filter="READ", this will only display processes which have the word
"READ" in one of the columns.

Returns fields for the JOBEXAM display.
Note that this query does not use a $v(-1,$j) mailbox message to
query processes. This avoids unecessary overhead.
This query may change in future versions.
Parameters:
JobNumber - Job number of where to start the query, default = 1 (first job)

Return PIDS for all processes running on the system.
This query returns the internal pid for each process on the system. This pid can
then be passed directly to the %OpenId() method, or as an argument to an embedded
SQL query which does a SELECT based on the Pid. See the example above for SQL useage.
Parameters:
JobNumber - Job number of where to start the query, default = 1 (first job)

The 'filter' parameter can be a variable name definition and/or subscript
definition, using * as wildcards. A filter name of '*' will return all
PPG variables for that process id.
As an example of using the wildcards, a filter specification of "CUST*(12*,*COOP*" would
mean return all PPG variables whose name starts with CUST, that have 2 or more subscripts,
the first subscript must start with 12, the second subscript must contain COOP.

pid can be any valid process id, or -1 for the caller's process.

options can be one or more of the following characters
"N" Do not return subscripts of a PPG, just return the root name
"B" Return the number of blocks used by the PPG (needs the "N" option)
"b" Returns the number of bytes used by the PPG (needs the "N" option)

Example
set rs=##class(%ResultSet).%New("%SYS.ProcessQuery:PPG")
do rs.Execute("*",$J,"NB")
for {
q:'rs.Next()
w "PPG name "_rs.GetData(1)_" is using "_rs.GetData(3)_" disc blocks",!
}
This query requires the %Admin_Manage:Use permission to execute.

Returns fields for the %SS display
Note that this query does not use a $v(-1,$j) mailbox message to
query processes. This avoids unecessary overhead.
This query may change in future versions.
Parameters:
JobNumber - Job number of where to start the query, default = 1 (first job)

Returns the top Processes as measured by the recent activity of either
CommandsExecuted or GlobalReferences

Parameters:
Sort - sort by "COMMANDS" (default) or "GLOREFS"
Number - number of processes to list. Default is 10 and max is 50

Note that the evaluation of the actual 'top' process list is handled by the
Application Monitor (%MONAPP) using the %Monitor.System.Dashboard2 class. This
is 'on' by default and can be managed using the %MONAPPMGR utility. Also, the
counts of CommandsExecuted and GlobalReferences returned are for the latest sample
period and not the total for the life of the process.

Returns the top Processes for certain types of database activity for the next 'n' seconds.
The query can be sorted by one of the following properties: 'GlobalReferences',
'GlobalUpdates', 'GlobalDiskReads', 'GlobalBlocks', or 'PrivateGlobalBlockCount'.

Parameters:
Sort - sort by "REFS", "UPDATES", "READS", "BLOCKS", "PPG". Default is "REFS".
Number - number of processes to list. Default is 20.
Seconds - number of seconds to wait. Default is 5 seconds.

The query will fetch the values for all processes, wait for 'n' seconds, and then
fetch the values again. It will return the list of the 'top' processes for the selected
'Sort' property, and the delta values for properties over that time period. Note that
PrivateGlobalBlockCount is returned as the total number used, not a delta.

Returns the variables of a process
Pass VariableName as a null string to return all variables.
This query requires the %Admin_Manage:Use permission to execute.
Parameters:
JobNumber - Job number to query.
NOTE: You may not use this query to examine your own job.
VariableName - Variable to return, or ""=All
Format - Bit string of how to format the variable data, default = 0 (no formattimg)
Bit 0 - Format the data with $c() and $lb() notation
Bit 1 - Embed bolded cursor sequences around $c() and $lb() notation
MaxRows - Maximum number of rows to return
Filter - Filters the data returned (case insensitive). If the variable contains the filter, then return it. ""=no filter
This query may change in future versions.

Returns the variables of a process, PID is decimal value for all platforms.
Pass VariableName as a null string to return all variables.
This query requires the %Admin_Manage:Use permission to execute.
Parameters:
Pid - Pid of process to query
VariableName - Variable to return, or ""=All
Format - Bit string of how to format the variable data, default = 0 (no formattimg)
Bit 0 - Format the data with $c() and $lb() notation
Bit 1 - Embed bolded cursor sequences around $c() and $lb() notation
MaxRows - Maximum number of rows to return
Filter - Filters the data returned (case insensitive). If the variable contains the filter, then return it. ""=no filter
Note that the fields returned here may change or be removed in future versions.