Using top instead of ps

Since time immemorial I have used the ps command to get information about processes from the shell. Under Ventura the ps command works in the Terminal. But for the shell I get an error

bash: /usr/bin/ps: No such file or directory

So how do I replace the command? My Goggle fu told me that I could use the top command. But I can’t get it to working in Xojo.

dim theShell as new Shell
theShell.Execute "/usr/bin/top|grep vserver_x64"
if theShell.ExitCode <> 0 then 
  MessageBox "problem with shell"
  Return
end if

The above code just hangs. If I use the -n 1 option it doesn’t even do anything in the Terminal.

Any other ideas? I need to check if Valentina Server is running or not.

I use this for top on macOS:

sh.Execute( "/usr/bin/top -l 1 | grep " + appName )

-l <samples>
Use logging mode and display samples, even if
standard output is a terminal. 0 is treated as infinity.
Rather than redisplaying, output is periodically printed in
raw form. Note that the first sample displayed will have an
invalid %CPU displayed for each process, as it is calculated
using the delta between samples.

I looked the help up and down. Thanks!

1 Like

“ps” is still available but Apple did change some paths in Ventura.
Use “whereis ps” or “type ps” in Terminal to see the new location.

1 Like

Actually, the problem was even weirder. ps in the shell works fine if the app is fully codesigned.

1 Like

top is great for figuring out what is sucking your Mac’s CPU dry, normally now some errant Apple sub process.

You may be able to using NSWorkspace and NSRunningApplications to get at vserver_x64, much quicker than using a shell instance, however NSRunningApplications doesn’t list all processes.