%SYS.ProcessQuery
persistent class %SYS.ProcessQuery extends %Library.Persistent, %SYSTEM.Help
SQL Table Name: %SYS.ProcessQuery
This class allows manipulation and display of InterSystems IRIS 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.
For example, the following open a process with a PID of 2078:
s Process=##CLASS(%SYS.ProcessQuery).%OpenId("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")
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.
#include %syPidtab
Set Rset = ##class(%ResultSet).%New("%SYS.ProcessQuery:ListPids")
d Rset.Execute()
While Rset.Next() {
&sql(SELECT CommandsExecuted,GlobalReferences INTO :CommandsExecuted,:GlobalReferences
FROM %SYS.ProcessQuery
WHERE Pid = :Rset.GetData(1))
i SQLCODE'=0 w !,"SQL Error "_SQLCODE continue ; 100 means process does not exist (halted)
w !,Rset.GetData(1)," ",CommandsExecuted," ",GlobalReferences
}
d Rset.Close()
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.
Property Inventory
- AppFrameInfo
- CPUTime
- CSPSessionID
- CanBeExamined
- CanBeSuspended
- CanBeTerminated
- CanReceiveBroadcast
- ClientExecutableName
- ClientIPAddress
- ClientNodeName
- CommandsExecuted
- CurrentDevice
- CurrentLineAndRoutine
- CurrentSrcLine
- DataBlockWrites
- EscalatedRoles
- GlobalBlocks
- GlobalDiskReads
- GlobalReferences
- GlobalUpdates
- InTransaction
- IsGhost
- JobNumber
- JobType
- JournalEntries
- LastGlobalReference
- LicenseUserId
- LinesExecuted
- Location
- LoginRoles
- MemoryAllocated
- MemoryPeak
- MemoryUsed
- NameSpace
- OSUserName
- OpenDevices
- Pid
- PidExternal
- PrincipalDevice
- Priority
- PrivateGlobalBlockCount
- PrivateGlobalReferences
- PrivateGlobalUpdates
- Roles
- Routine
- StartupClientIPAddress
- StartupClientNodeName
- State
- Switch10
- UserInfo
- UserName
Method Inventory
- ExamStackByPid()
- GetAppFrameInfo()
- GetCPUTime()
- GetInternalStackLevel()
- GetLoginRoutine()
- GetOSUsername()
- GetOpenDevices()
- GetVariableList()
- KillAllPrivateGlobals()
- NextProcess()
- Open()
- VariableDataFlags()
- VariableQuery()
- VariableValue()
Parameters
Properties
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.
Flag checked by JOBEXAM and Management Portal to see if a process can be examined in detail.
Flag checked by JOBEXAM and Management Portal to see if a process can be suspended.
Flag checked by JOBEXAM and Management Portal to see if a process can be terminated.
Flag checked by JOBEXAM and Management Portal to see if a process can receive a broadcast. Usually this means they are attached to a terminal.
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 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 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.
Total number of commands which the process has executed.
Current device that the process has open and is USEing via the USE command.
Current line and routine that the process is executing. Returned in +number^routine format.
This property requires a mailbox message to be sent to the process being examined.
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.
Total number of new database blocks the process has allocated. An indication of database growth.
Total number of times the process has fetched data from disk.
Total number of global references the process has made.
Total number of global updates (sets and kills) the process has made.
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.
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, there 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.
Used as an index into the job table. May be passed to the Open() method to open an object instance to that process.
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:
If Process.JobType=$$$WDTYPE w !,"Process is the write daemon"
Total number of journaled global updates the process has recorded. An indication of journal file growth.
Last global reference that the process made.
This property requires a mailbox message to be sent to the process being examined.
The User ID which took out the license for the process.
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.
If a system process, will be the system processes name.
If a user process, will be the value of $g(^%IS(0,Job.CurrentDevice),"")
Roles a process has when it initially logs in.
Maximum amount of memory in KB that the process is allowed to use.
This property requires a mailbox message to be sent to the process being examined.
This property requires a mailbox message to be sent to the process being examined.
Current amount of memory the process has used in KB.
This property requires a mailbox message to be sent to the process being examined.
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.
List of devices which the process has opened. Returned as a comma separated string.
If any device name in the list contained ",", users won't be able to parse the list. Users should use $LFS(OpenDevices,",",2) to convert the comma separated string to a $List() format string in order to get each device in the list.
This property requires a mailbox message to be sent to the process being examined.
Process ID ($J) given to the process by the O/S, decimal form on all platforms.
This property requires a mailbox message to be sent to the process being examined.
Priority of the process at the O/S level.
This property contains the # of database blocks currently allocated to store process private globals.
Total number of private global references the process has made.
Total number of private global updates (sets and kills) the process has made.
Roles a process currently has.
Name of the routine which the process is currently executing.
IP address of the client as detected on the TCP channel by the server process.
IP Node name of the client as detected on the TCP channel by the server process.
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 - Global Set $Bit
BGET - Global $Bit
EVT - Waiting on event
SLCT - $System.Socket wait
SEM - $System.Semaphore wait
IPQ - Inter-process queue wait
DEQ - Dequeue wait (currently unusued)
VSET - Global Set vector element
VKLL - Global Kill vector element
RUN - Process is running in none of the aformentioned states
The following flags can be appended to the state:
NL - Net lock waiting
DT - The dead job has open transaction
S - Suspension requested
GW - Global Wait
NR - Net Read
D - Dead
H - Halting
NH - Netharden
N - Remote network
W - Hibernating
This property is set to 1 if the process has set switch 10.
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.
$Username of the process as set by the processes authentication method.
Methods
Parameters:
Pid - Process ID ($J) of the process to examine
GetVariables - Flag specifies variable and/or object info 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) - top of subtree containing information of 'variable' defined at 'base' level
The function call $$VGetn^%STACK(index,l,v) returns information about the value of variable 'v' at stack level 'l'. If the variable is a private local variable then argument 'v' must be string starting with a tilde character, "~", followed by the variable identifier text. The variable 'v' can include a parenthesized list of subscript literals. Note that lookup of a subscripted local variable requires that the examined process and the examining process are using the same local collation. It returns "" if the variable 'v' is undefined at that stack level; otherwise it returns $LISTBUILD(flags,value) where 'value' is the value of the variable and 'flags' is a sequence of flag letters. If flags["O" then the variable contains an oref and 'value' is the oref string representation.
If objects are requested:
("*CLASS",class) = number of active local objects in Class 'class'
("*CLASS",class,oref) = "" is defined if 'oref' value is a local object of class 'class'. The function call $$OGetn^%STACK(index,oref,property) returns $LISTBUILD(flags,value) if the object 'oref' has a property name 'property' and it returns "" if either the oref or the property does not exist. If the property is multidimensional then the property name can include a parenthesized list of subscript literals. Note that lookup of a subscripted multidim property requires that the examined process and the examining process are using the same local collation. The 'value' of the returned $LIST is usually the value of the property (see 'flags'.) The 'flags' of the returned $LIST is a sequence of flag letters.
Pid - Pid (decimal) of the process
Return Value:
The application frame information in $LIST form.
or CPU time for the process specified by pid (with method arguments)
Parameters:
pid (optional) - JobNumber (integer +$J)
of the IRIS process you want to get information about
Return Value:
Returns two comma-delimited pieces, "system" CPU time and "user" CPU time Time is returned as milliseconds of CPU time.
0,0 is returned if the specified pid does not exist.
The default for stack is the current $STACK value.
When there are NEW commands in a level, each NEW command creates a new internal stack level without increasing $STACK. This method returns the highest internal stack level for the given $STACK. If there are other internal levels created by NEW commands within the given $STACK, they are returned in the newlevels argument as a $LIST of values. There may be different variables defined at each of those levels and the same variable may have different values at each 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.
Parameters:
Pid - Process ID ($J) of the process to examine
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.
The list is returned as nodes of the listvar argument.
listvar will be set to the number of sublists.
listvar(1) will be set to the first sublist, listvar(2) to the second, etc.
Each sublist is a $List of variable entries.
Each variable entry is a $ListBuild(name,$Data(name)).
Private variables are identified with a tilde (~) as the first character in the name.
The names are not sorted, except private variables follow the public variables.
The return value of the method is the total number of variables in the sublists.
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))
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.
The variable reference may include subscripts.
To get the value for a private variable, add a tilde in front of the name, as in "~info".
The variable reference may include subscripts.
To operate on a private variable, add a tilde in front of the name, as in "~info".
The variable reference may include subscripts.
To get the value of a private variable, add a tilde in front of the name, as in "~info".
If the variable is undefined an <UNDEFINED> error will be thrown.
Queries
SELECT * FROM %SYS.ProcessQuery
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.
Note that this query does not use a $v(-1,$j) mailbox message to query processes. This avoids unnecessary 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.
Note that this query does not use a $v(-1,$j) mailbox message to query processes. This avoids unnecessary overhead. This query may change in future versions.
Parameters:
JobNumber - Job number of where to start the query, default = 1 (first job)
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 usage.
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.
Note that this query does not use a $v(-1,$j) mailbox message to query processes. This avoids unnecessary overhead. This query may change in future versions.
Parameters:
JobNumber - Job number of where to start the query, default = 1 (first job)
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.
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.
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 formatting)
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.
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 formatting)
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.
Parameters:
'InternalStack' is a value less than or equal to the current stack level, as reported by the %STACK utility. If no stack level is given, the current stack level is the default.
'Type' is the kind of query to run. The default is 0 which returns a sorted list of variables. Type 1 returns an unsorted list and may be quicker because it uses no global variables.
The query returns only plain variable names without subscripts. Private variables are distinguished from public variables by a tilde prefix. Thus the private variable 'info' will be presented as '~info'. All private variables are returned after all public variables.
Indexes
Uses NextProcess(Pid) to retrieve next process id.
Inherited Members
Inherited Methods
- %AddToSaveSet()
- %AddToSyncSet()
- %BuildDeferredIndices()
- %BuildIndicesAsync()
- %BuildIndicesAsyncResponse()
- %CheckConstraints()
- %CheckConstraintsForExtent()
- %ClassIsLatestVersion()
- %ClassName()
- %ComposeOid()
- %ConstructClone()
- %Delete()
- %DeleteExtent()
- %DeleteId()
- %DispatchClassMethod()
- %DispatchGetModified()
- %DispatchGetProperty()
- %DispatchMethod()
- %DispatchSetModified()
- %DispatchSetMultidimProperty()
- %DispatchSetProperty()
- %Exists()
- %ExistsId()
- %Extends()
- %GUID()
- %GUIDSet()
- %GetLock()
- %GetParameter()
- %GetSwizzleObject()
- %Id()
- %IsA()
- %IsModified()
- %IsNull()
- %KillExtent()
- %LockExtent()
- %LockId()
- %New()
- %NormalizeObject()
- %ObjectIsNull()
- %ObjectModified()
- %Oid()
- %OnBeforeAddToSync()
- %OnDeleteFinally()
- %OnDetermineClass()
- %OnOpenFinally()
- %OnSaveFinally()
- %Open()
- %OpenId()
- %OriginalNamespace()
- %PackageName()
- %PurgeIndices()
- %Reload()
- %RemoveFromSaveSet()
- %ResolveConcurrencyConflict()
- %RollBack()
- %Save()
- %SaveDirect()
- %SerializeObject()
- %SetModified()
- %SortBegin()
- %SortEnd()
- %SyncObjectIn()
- %SyncTransport()
- %UnlockExtent()
- %UnlockId()
- %ValidateIndices()
- %ValidateObject()
- %ValidateTable()
- Help()
Storage
Storage Model: SQLStorage
Maps: 1
Map number 1 is named Map1
thismap.Global:
({Pid})
|
= |
|