Ah, apologies ( that's what I get for trying to send emails during bedtime 🙂 )

I have been bitten in the past by arg differences between different Unix flavors. I have tried the following on Mac OS 12.something with just the BaseX jar download.

let $ps := proc:execute('ps', ('-o', 'pid,%cpu,command'))
return $ps

<result>
  <output>  PID  %CPU COMMAND
82437   0.0 -bash
82462  16.7 /usr/bin/java -jar BaseX107.jar
</output>
  <code>0</code>
</result>

This is a borrowed Mac - I didn't install anything. Does your Mac not have a ps; e.g. `which ps`? This one returns `/bin/ps`.

Sorry for the noise.
Best,
Bridger

On Thu, Oct 19, 2023, 8:00 PM Bridger Dyson-Smith <bdysonsmith@gmail.com> wrote:
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('&#x0a;'))

  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