Hi Eliot - hope you're well!
Quickly off the cuff, the `ps` command on MacOS is a BSD-flavo(u)r, if I'm remembering correctly (it's been a while...).
I don't have a Mac handy right now, but check this `ps` man page - https://ss64.com/osx/ps.html - your args may need to be adjusted.
Hope that's helpful. Best, Bridger
On Thu, Oct 19, 2023, 7:08 PM Eliot Kimber eliot.kimber@servicenow.com wrote:
In the context of a 10.6 server running as a web app, I’m trying to implement a function that uses the process module to run commands to get information about the running BaseX servers, in particular, the PID and port each server is on. I start a number of “worker” BaseXHTTP instances to handle long-running processes.
On Linux this code works:
let $cmdResult := proc:execute(‘ps’, ('-o', 'pid,%cpu,command'))
From which I can parse out the PID and port for BaseX processes:
let $lines as xs:string* := ($cmdResult/output/text() => tokenize('
'))
return
map{
'data' : let $servers as map(*) := map:merge( for $line at $p in $lines[contains(., 'BaseXHTTP')] let $pid as xs:string := tokenize($line, '\s+')[1] let $port as xs:string := tokenize(substring-after($line, '
-p'),'\s+')[1]
return map{ $port : map{ 'port' : $port, 'pid' : $pid } } ) return $servers
}
However, on macOS there’s not an exact equivalent of the linux version of ps, but there is the “pgrep” command, which, from the command line, lets me get the data I need:
pgrep -lf basex
However, when I try to run this from within BaseX, I get “sysmon request failed with error: sysmond service not found pgrep: Cannot get process list”
I assume this is a function of how the HTTP servers are running on macOS. I’m starting them like so:
"${basexBinDir}/basexhttp" ${debugFlag} -S -p${clientPort} -h${httpPort} -s${stopPort} &
So as a service
Any ideas how I might make this work on mapOS?
Thanks,
Eliot
*Eliot Kimber*
Sr Staff Content Engineer
O: 512 554 9368
M: 512 554 9368
servicenow.com https://www.servicenow.com
LinkedIn https://www.linkedin.com/company/servicenow | Twitter https://twitter.com/servicenow | YouTube https://www.youtube.com/user/servicenowinc | Facebook https://www.facebook.com/servicenow