Article
· Aug 17, 2023 1m read

How to get the list of processes programmatically

InterSystems FAQ rubric

It can be obtained using AllFields query of %SYS.ProcessQuery class.

For the details, please refer to the document Process (Job)【IRIS】Process (Job).

An example of execution in the terminal is as follows.

USER>set stmt=##class(%SQL.Statement).%New()
USER>set st=stmt.%PrepareClassQuery("%SYS.ProcessQuery","AllFields")
USER>write st   // you can call %Execute() when st = 1
1
USER>set rset=stmt.%Execute()
USER>while rset.%Next() { write rset.%Get("JobNumber"),"-",rset.%Get("Pid"),"-",rset.%Get("OSUserName"),"-",rset.%Get("CurrentDevice"),"-",rset.%Get("Routine"),"-",rset.%Get("State"),"-",rset.%Get("UserName"),!}

For example, the same as a method.

ClassMethod ShowJob()
{
 set stmt=##class(%SQL.Statement).%New()
 set st=stmt.%PrepareClassQuery("%SYS.ProcessQuery","AllFields")
 set rset=stmt.%Execute()
 while rset.%Next() {
   write rset.%Get("JobNumber"),$Char(9)
   write rset.%Get("Pid"),$Char(9)
   write rset.%Get("OSUserName"),$Char(9)
   write rset.%Get("CurrentDevice"),$Char(9)
   write rset.%Get("Routine"),$Char(9)
   write rset.%Get("State"),$Char(9)
   write rset.%Get("UserName"),!
 }
}
Discussion (2)1
Log in or sign up to continue