• 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: Get PID from Socket Descriptor?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Get PID from Socket Descriptor?


  • Subject: Re: Get PID from Socket Descriptor?
  • From: Charlie Boisseau <email@hidden>
  • Date: Mon, 9 May 2005 21:12:21 +0100

Thanks for your answer. I think I'll have to go back to using the fstat tool, which means including it in the application bundle for compatibility with 10.4. My only other option is to take out the feature completely. I'd be a bit aggrieved if this has to happen because for my Windows port, the netstat command has the functionality built-in (the -o switch).

Does anyone know how the fstat tool does it? It seems to work quickly enough.

Cheers.

--
Charlie Boisseau


On 9 May 2005, at 18:01, Quinn wrote:

I don't think you'll find a nice solution to this problem. Apple knows about this issue <rdar://problem/2655113>; we need similar functionality to tell you what files are open on a volume when you can't eject it (a traditional Mac OS feature that's sorely missed on Mac OS X). However, we haven't yet got around to implementing the correct solution (an API to get this information from the kernel in an implementation independent fashion).

"lsof"'s approach is definitely not the right one. It works by grovelling around in kernel memory. This is why a) it's slow, and b) it's rev-locked to the kernel implementation (every time we change a structure inside the kernel, we have to rebuild "lsof").

For your needs, exec'ing "lsof" represents a pseudo-API to solve this problem. However, as you've noticed, exec'ing command line tools is not really an API. Moreover, peeling a layer off "lsof" (that is, doing what it does) is not a viable solution because of point b) above.

You could solve this problem by loading code into the kernel, but even that would be pretty ugly (you'd either get binary compatibility or being able to identify sockets that were created before you loaded, but not both). And, as a GUI programmer, I'm sure you're not too thrilled about writing kernel code.

Sorry I don't have better news.

_______________________________________________ Do not post admin requests to the list. They will be ignored. Macnetworkprog mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: Get PID from Socket Descriptor?
      • From: Quinn <email@hidden>
    • Re: Get PID from Socket Descriptor?
      • From: Justin Walker <email@hidden>
References: 
 >Re: Get PID from Socket Descriptor? (From: Charlie Boisseau <email@hidden>)
 >Re: Get PID from Socket Descriptor? (From: Quinn <email@hidden>)

  • Prev by Date: Re: Get PID from Socket Descriptor?
  • Next by Date: Re: Get PID from Socket Descriptor?
  • Previous by thread: Re: Get PID from Socket Descriptor?
  • Next by thread: Re: Get PID from Socket Descriptor?
  • Index(es):
    • Date
    • Thread