0

My macOS app can launch a faceless helper application which is shipped in its Contents/Library/LoginItems using Apple's Service Management Framework, as described in Apple documentation. Funny thing is, when I request the unix ps program to give me the command/paths, for this helper process, it gives the bundle identifier instead. Example:

jk$ ps -x -o command
...
com.mycompany.MyAgent
...

It gives me the same answer with or without the -c option on ps.

Because my app comes in several flavors and versions which each contain different helpers, and because users may have multiple installations, and because of the sometimes strange behavior of Launch Services, for self-testing and diagnostic purposes, I would like to get the path to the running helper's package or executable.

Why does ps give the bundle identifier instead? How can I get the path?

Jerry Krinock
  • 4,860
  • 33
  • 39

1 Answers1

1

A program can a) rewrite the memory pointed to by argv and the strings it points to, and/or b) call setprogname().

I seem to recall that setprogname() does not affect the output of ps, but rewriting argv does. I could have that backwards, though. I know that Wine does both and affects the command that ps sees.

Ken Thomases
  • 88,520
  • 7
  • 116
  • 154
  • Wow, that is wild, Ken. My helper app certainly does not touch `argv` nor call `setprogname()`. However, this is interesting, because certainly such manipulations are somehow within the powers of Apple's *launchd*. – Jerry Krinock Nov 15 '18 at 01:07
  • Launchd might do it. So might XPC in the launched service, somehow. – Ken Thomases Nov 15 '18 at 04:13