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

LinkedIn | Twitter | YouTube | Facebook