• 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: Finding process path from Cocoa?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Finding process path from Cocoa?


  • Subject: Re: Finding process path from Cocoa?
  • From: Alastair Houghton <email@hidden>
  • Date: Wed, 9 Dec 2009 09:53:11 +0000

On 9 Dec 2009, at 00:14, Nick Zitzmann wrote:

> On Dec 8, 2009, at 5:03 PM, Laurent Daudelin wrote:
>
>> Is there any way I can find what's the path of a given process running? A background process, which cannot be retrieved in [[NSWorkspace sharedWorkspace] launchedApplications]?
>
> Yes. ([[[NSProcessInfo processInfo] arguments] objectAtIndex:0])

No, no, no and thrice no.

What that gives you is the content of argv[0], which *is not* (necessarily) the path to your program.  If you think it is, then to disabuse you of the notion I can write a program like this:

  #include <unistd.h>

  int
  main (void) {
    execl ("/Applications/YourApp.app/Contents/MacOS/YourApp",
	   "This is not my path",
	   NULL);
  }

and what you'll discover (probably to your horror) is that the above gives the result

  @"This is not my path"

as for that matter would accessing argv[0] from your main() function.

Obviously it's equally possible to substitute any old path rather than the string "This is not my path".

It is possible to get the path to your executable using the dyld API, but before doing such a thing you need to be very clear as to why you need it and what it is that you're going to do with it.  It's very easy to end up with major security holes or just plain broken behaviour.

Kind regards,

Alastair.

--
http://alastairs-place.net



_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Finding process path from Cocoa?
      • From: "email@hidden" <email@hidden>
    • Re: Finding process path from Cocoa?
      • From: "email@hidden" <email@hidden>
References: 
 >Finding process path from Cocoa? (From: Laurent Daudelin <email@hidden>)
 >Re: Finding process path from Cocoa? (From: Nick Zitzmann <email@hidden>)

  • Prev by Date: Re: NSURLConnection Problem Inside QuickLook Generator
  • Next by Date: Re: Finding process path from Cocoa?
  • Previous by thread: Re: Finding process path from Cocoa?
  • Next by thread: Re: Finding process path from Cocoa?
  • Index(es):
    • Date
    • Thread