Question Evan Gabhart · Mar 13, 2025

How do I get the name of the OS user used by the IRIS superserver?

Is there a way in ObjectScript to return the OS user of the superserver? I know %SYS.ProcessQuery can find this for a given process but is there a clean way independent of a specific process ID I can find the OS user used for background jobs?

For IRIS this is usually irisusr and Caché this is usually cacheusr but may vary based on installation and upgrade history of an instance. I would find it very useful to determine programmatically if a process is running as this particular user when the username may vary.

Comments

Julius Kavay · Mar 13, 2025

Try this method

Class DC.Util Extends%RegisteredObject
{

/// Return: the OS username for this Cache/IRIS instance/// 	/// First, get the port of the superserver/// then search, which job owns that port/// then return the OSUsername for that job/// ClassMethod OSUsername()
{
	new$namespaceset$namespace="%SYS"if##Class(Config.Startup).Get(.par),$d(par("DefaultPort"),port) {
		setjob="", pattern=".e1""|TCP|"_port_"*"".e"forsetjob=$zj(job) quit:$v(-1,job)?@pattern||(job="")
		
		ifjob {
			set proc=##class(%SYS.ProcessQuery).%OpenId(job)
			ret:proc proc.OSUserName
		}
	}
	ret ""
}

}

A note:
- I know of a $zu(...) function which works and returns the superserver port but $zu() functions are  deprecated/discouraged  
- and this one is not in the replacement list - why?

0
Alice Shrestha · Mar 13, 2025

Maybe something like this,

$SYSTEM.Process.UserName($ZJ(""))

0
Evan Gabhart  Mar 14, 2025 to Ben Spead

I found no direct documentation but got some information from the method documentation of the NextProcess class method in %SYS.ProcessQuery:

https://docs.intersystems.com/iris20243/csp/documatic/%25CSP.Documatic…

So, it seems passing an argument works like $order on the list of running processes with the caveat a halted process is treated like $zjob("") and returns the first process id in the list. I think this will do the trick, thanks Alice!

0
Ben Spead  Mar 14, 2025 to Evan Gabhart

do we know that the "1st process" is?  Is there a specific daemon which is always considered first?  This only would list PIDs running iris (not all PIDs on the OS), correct?

0
Evan Gabhart  Mar 14, 2025 to Ben Spead

Thank you for asking this, Ben. The superserver is not the first process and comes after auxiliary write daemons. I also found multiple cases for instances that upgraded from Caché to IRIS where the first process uses cacheusr but the superserver uses irisusr. So this will not work. I think we may be stuck with looking for the superserver process.

0
Evan Gabhart  Mar 14, 2025 to Alice Shrestha

See my reply to Ben, below. Unfortunately it seems the first process is not necessarily correct for instances with an upgrade history from Caché to IRIS.

0
Alice Shrestha  Mar 16, 2025 to Evan Gabhart

Not sure what the use case here is, but you could also just run a SQL query on the process query table as well: 

&SQL(SELECT OSUserName Into :OSUserName FROM %SYS.ProcessQuery where JobType = 24)

0
Julius Kavay · Mar 13, 2025

There is a somewhat "simple" method too

/// search for the superserver job/// return the OS Username for that jobClassMethod OSUsername()
{
	new$namespaceset$namespace="%SYS"setjob=""for {setjob=$zj(job) quit:job=""set prc=##class(%SYS.ProcessQuery).%OpenId(job)
		if prc, prc.JobType=24 ret prc.OSUserName
	}
	ret ""
}
0
Timo Lindenschmid · Mar 13, 2025

Hi Evan,

i think the only way is using process query like this:
set currentUser = ##class(%SYS.ProcessQuery).%OpenId($job).OSUserName
 

0
Luis Angel Pérez Ramos · Mar 14, 2025

You can use $ZF(-100) command to execute operative system commands (here an example), with that command you can look for the process that is locking the superserver.

0
Vitaliy Serdtsev · Mar 14, 2025
$SYSTEM.Process.UserName(##class(%SYS.ProcessQuery).NextProcess(""))
0