3 Replies
      Latest reply on Jul 26, 2017 2:18 AM by eskimo
      ocworld Level 1 Level 1 (0 points)

        I've tryed to implement a process monitor application like the "Activity Monitor.app"

         

        How to get detailed information of other processes in C or Objective-C?

         

        "NSRunningApplication" is not enough. It's because It provided limited information.

         

        I wanna catch detailed information such as cpu usages and command line including arguments.

         

        After googled, therefore, I know that "libproc" exists. However, it is hard to find official document about it like man page.


        What is official method to get a variety of data about other processes?

         

        Please, help me! ;-)

        • Re: How to get detailed information of other processes in C or Objective-C?
          eskimo Apple Staff Apple Staff (10,285 points)

          Do you plan to deploy to the Mac App Store?  Or via Developer ID?

          Share and Enjoy

          Quinn “The Eskimo!”
          Apple Developer Relations, Developer Technical Support, Core OS/Hardware
          let myEmail = "eskimo" + "1" + "@apple.com"

            • Re: How to get detailed information of other processes in C or Objective-C?
              ocworld Level 1 Level 1 (0 points)

              I have a plan to deploy via Developer ID without Mac App Store.

               

              However, also, I have wonder that is it possible to provide detailed other running processes infomation.

                • Re: How to get detailed information of other processes in C or Objective-C?
                  eskimo Apple Staff Apple Staff (10,285 points)

                  I have a plan to deploy via Developer ID without Mac App Store.

                  Good.  Doing this in a Mac App Store app would be tricky.

                  What is official method to get a variety of data about other processes?

                  There isn’t a recommended way of doing this.  My recommendation is that you not create this app.  It’s impossible to create such an app without it being tightly bound to the underlying implementation details of the OS.  That means that every time we release a new version of the OS you will have to revise your app to account for those changes.  This is not a good way to live.

                  And when I say impossible I mean fundamentally impossible.  The issue isn’t that specific APIs are broken or missing (although there’s plenty of that, as I’ll discuss below) but that the system can change in ways that cause your app to start showing meaningless data.

                  For a concrete example, consider compressed virtual memory.  In 10.9 we added support for compressed virtual memory.  This is an entirely new concept, so there’s no way that an app showing virtual memory statistics could possibly show meaningful results without being specifically revised for 10.9.

                  This is just one example of the problem: if you go down this path, you will encounter many more, both historical and in future OS releases.


                  Given this reality, Apple has not put a lot of effort into providing APIs for getting this sort of information.  What APIs that do exist were either inherited from OS X’s predecessor OSs or were added primarily to meet our internal requirements rather than the needs for third-party developers.  Thus, you will find a lot of places where this APIs are:

                  • incomplete

                  • incorrect

                  • poorly documented

                  • aren’t as binary compatible as they should be

                  libproc is a good example of this.  AFAIK it has no documentation (although the header comments in <libproc.h> should be good enough to get you started).  The first time I used libproc I discovered an edge case that kernel panicked the system )-:  Later on I found that some corner case within libproc had changed in a binary incompatible fashion.  Fun times!


                  If you have questions about how to get some specific piece of info, post them here and I’ll try to answer them.  But, hey, don’t say you weren’t warned.

                  Share and Enjoy

                  Quinn “The Eskimo!”
                  Apple Developer Relations, Developer Technical Support, Core OS/Hardware
                  let myEmail = "eskimo" + "1" + "@apple.com"

                  1 of 1 people found this helpful