• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Talking to the Dock
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Talking to the Dock


  • Subject: Re: Talking to the Dock
  • From: "M. Uli Kusterer" <email@hidden>
  • Date: Tue, 29 Jul 2003 16:46:13 +0200

At 8:42 Uhr -0400 29.07.2003, Sailor Quasar wrote:
I'm reasonably sure there's no Cocoa wrapper around it, but it would probably be simpler to use NSTask to shell out to the 'ps' command. sysctl() is a complicated set of multi-level options and data structures, but the output of ps can be parsed easily since it's possible to request specific information from ps and the output can be distilled further using pipes into awk and grep. The only reason to use sysctl() directly would be if speed is critical to the code in question.

Maybe I spend too much time implementing parsers and have thus grown allergic to them, but I generally find it much more convenient (and reliable) to call "real" APIs than to call through to a command-line tool.

Not to mention that I'm of the faction that says that speed is always critical in application software, at least where it doesn't make the code unreadable. I wouldn't switch to inline-assembly if it's not really necessary, but otherwise I see no point in needlessly hogging the user's CPU needlessly. I have enough applications that hog the CPU excessively and without which I can't do. So chances are that if your app needs more CPU than is warranted by its function, I'll throw it away.

But yes, if you don't care about subtle changes in the output of "top" or "ps" screwing up your parsing, and you enjoy writing parsers that take apart information that can be received already dissected from a system API, and you don't care about it taking a little longer, NSTask is a solution as well.

But if you want to see an example of a parser that isn't good enough, check out the way PB doesn't report missing symbols. It simply says "build failed" and leaves you to look in the raw gcc output what actually went wrong...

Anyway, if you want some sample code that uses sysctl(), I posted some code about a year ago that detects whether the screen saver is running. If you can't find it in the archives, holler and I'll put it up on my web site.
--
Cheers,
M. Uli Kusterer
------------------------------------------------------------
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
  • Follow-Ups:
    • Re: Talking to the Dock
      • From: Sailor Quasar <email@hidden>
References: 
 >Re: Talking to the Dock (From: Sailor Quasar <email@hidden>)

  • Prev by Date: Re: Syntax Colouring
  • Next by Date: Re: Memory Management
  • Previous by thread: Re: Talking to the Dock
  • Next by thread: Re: Talking to the Dock
  • Index(es):
    • Date
    • Thread