Question
· Mar 13

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.

Discussion (12)3
Log in or sign up to continue

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 $namespace
	set $namespace="%SYS"
	
	if ##Class(Config.Startup).Get(.par),$d(par("DefaultPort"),port) {
		set job="", pattern=".e1""|TCP|"_port_"*"".e"
		for  set job=$zj(job) quit:$v(-1,job)?@pattern||(job="")
		
		if job {
			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?

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.c...

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!