• 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 17:15:42 +0100

OK, I've been trying lsof; it seems to provide me with what I need, but it's slow and doesn't show everything like fstat.

This is what I want to achieve:

I have a GUI app which uses the netstat tool to display current socket usage. The thing which is lacking from the OS X netstat implementation is the owner process. I need a function which will either list all sockets and their owner pid, so I can match them against my results from netstat. Or, I need a function witch provides me with the owner pid of a given socket descriptor (that comes from netstat).

I looked at the fstat function (in sys/stat.h), however the returned structure doesn't seem to contain the owner pid:

struct stat {
dev_t st_dev; /* device inode resides on */
ino_t st_ino; /* inode's number */
mode_t st_mode; /* inode protection mode */
nlink_t st_nlink; /* number or hard links to the file */
uid_t st_uid; /* user-id of owner */
gid_t st_gid; /* group-id of owner */
dev_t st_rdev; /* device type, for special file inode */
struct timespec st_atimespec; /* time of last access */
struct timespec st_mtimespec; /* time of last data modification */
struct timespec st_ctimespec; /* time of last file status change */
off_t st_size; /* file size, in bytes */
quad_t st_blocks; /* blocks allocated for file */
u_long st_blksize;/* optimal file sys I/O ops blocksize */
u_long st_flags; /* user defined flags for file */
u_long st_gen; /* file generation number */
};


I'd like to minimize the amount of (slow) shell processes I involve. Any ideas would be gratefully appreciated.

Cheers.

--
Charlie Boisseau



On 30 Apr 2005, at 20:44, Justin Walker wrote:


1) 'man lsof'
2) go to the darwin website and get the source for fstat; it should be in the diskdevs project. If it really isn't in 10.4, try 10.3.x (darwin 7.x)




_______________________________________________
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>
  • Prev by Date: Strange Network Mounts
  • Next by Date: Re: Get PID from Socket Descriptor?
  • Previous by thread: Strange Network Mounts
  • Next by thread: Re: Get PID from Socket Descriptor?
  • Index(es):
    • Date
    • Thread