Indika Bandara Udagedara wrote:
> --- In [email protected], "Paul Herring" <[EMAIL PROTECTED]> wrote:
>> On Wed, Aug 27, 2008 at 6:29 AM, Thomas Hruska <[EMAIL PROTECTED]> wrote:
>>> Amitabh Shukla wrote:
>>>> Greetings
>>>>
>>>> I need to get the process name that is using an open port on Windows
>>>> and Unix programatically in C. On unix I think the best way may be
>>>> read the /proc fs.(I would be glad to know of a better/more portable
>>>> way.) I don't know how to obtain that information on Windows.
>>>> Please help me with some pointers on how to go about it.
>>>>
>>>> Thanks,
>>>> AS
>>> Hmm...not sure about *NIX, but the simplest way would be to
> capture the
>>> output of 'netstat -o' under Windows (Win2000 and later) and then
> parse
>>> it.  'netstat' exists for *NIX, but I don't know if it maps open
> sockets
>>> to process IDs.  That would be the most portable (albeit "hacky")
> method.
>> netstat -p
>>
>> -- 
>> PJH
>>
>> http://shabbleland.myminicity.com/
>>
> 
> why not lsof ?

That could work too.  'netstat' is more likely to be installed. 
Regardless, the point of this discussion is that there is no very 
"portable" method of doing it and any APIs that the OS may or may not 
expose may or may not be documented.  Any APIs that are exposed are also 
likely going to be difficult to use as they will tend to dig around in 
the nitty-gritty details of the OS.  It would be best to let an external 
program handle those parts.  'lsof' doesn't exist on Windows but the OP 
could write multiple parsers to cover a larger set of scenarios.

-- 
Thomas Hruska
CubicleSoft President
Ph: 517-803-4197

*NEW* MyTaskFocus 1.1
Get on task.  Stay on task.

http://www.CubicleSoft.com/MyTaskFocus/

Reply via email to