• 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: Is this program open?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Is this program open?


  • Subject: Re: Is this program open?
  • From: Darkshadow <email@hidden>
  • Date: Fri, 14 Apr 2006 05:09:08 -0400


On Apr 13, 2006, at 5:14 PM, John Stiles wrote:


On Apr 13, 2006, at 2:10 PM, John Stiles wrote:

On Apr 13, 2006, at 12:34 PM, Tom Harrington wrote:

When I had to do something similar, I used sysctl(3).  Apple gives a
nice example of how to do this at
http://developer.apple.com/qa/qa2001/qa1123.html

This is a great reference. I will check this out. Thank you for the info.

Wait, hold on. I was looking up kinfo_proc and found the following warning:
http://developer.apple.com/qa/qa2004/qa1361.html


IMPORTANT: Because the definition of the kinfo_proc structure (in <sys/sysctl.h>) is conditionalized by __APPLE_API_UNSTABLE, you should restrict use of the above code to the debug build of your program.

So maybe this is a bad idea...!?


Hmm, it's been like that for a while now. I can remember clearly that it was labeled the same way in 10.2, and may have been before that as well. It's probably safe enough to call on.

I've written up a few functions to get process info using sysctl, and one of the things it'll do is grab the process arguments. The first argument (on OS X 10.4 and before, at least) is always the full path to the executable - even if it was invoked without a full path. It'd still be a static attribute, a record of the path when the executable was launched rather than the current path. You say that doesn't concern you much, so here ya go.

As stated by someone else, you can only grab the process arguments for processes running under the same user the code is running under, unless you're root.

You can download it or view the code online from my site: <http:// homepage.mac.com/darkshadow02/developer.htm> (It's DSProcessesInfo). Code is free to use, or you can just use it as a base to make your own up.

As a side note, and important for you John, the function that gathers the process arguments purposefully skips over the first argument. I did it to have it mirror the output from ps. It's a trivial change to have it include that info if you want to use the functions. If you're using it as a base for your own code, look at the function nameForProcessWithPID() - it uses that first argument.


Darkshadow (aka Michael Nickerson)


Attachment: smime.p7s
Description: S/MIME cryptographic signature

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Is this program open? (From: John Stiles <email@hidden>)
 >Re: Is this program open? (From: "Tom Harrington" <email@hidden>)
 >Re: Is this program open? (From: John Stiles <email@hidden>)
 >Re: Is this program open? (From: "Tom Harrington" <email@hidden>)
 >Re: Is this program open? (From: John Stiles <email@hidden>)
 >Re: Is this program open? (From: John Stiles <email@hidden>)

  • Prev by Date: Append bytes to a file
  • Next by Date: Re: Binding NSTextField to NSURL
  • Previous by thread: Re: Is this program open?
  • Next by thread: Re: Is this program open?
  • Index(es):
    • Date
    • Thread