473,406 Members | 2,336 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Lookup PID from Port.

Does anyone know if you can lookup the PID that owns a socket (based
on port number) programmatically? I know most systems have LSOF for
this but I'd like it to be more portable and not call an external
program.
Jun 27 '08 #1
3 1836
On 6 Jun 2008 at 22:49, Jason8 wrote:
Does anyone know if you can lookup the PID that owns a socket (based
on port number) programmatically? I know most systems have LSOF for
this but I'd like it to be more portable and not call an external
program.
I can't think off-hand of a library that does this, strange to say. I'd
advise you to have a look at the source code to netstat on your platform
(e.g. on Debian it's in the net-tools package) and pick out the bits
where it does the relevant magic.

Jun 27 '08 #2
Jason8 <ja*********@gmail.comwrites:
Does anyone know if you can lookup the PID that owns a socket (based
on port number) programmatically? I know most systems have LSOF for
this but I'd like it to be more portable and not call an external
program.
The C language itself doesn't define PIDs, sockets, or port numbers.

Try comp.unix.programmer.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jun 27 '08 #3
In article <ln************@nuthaus.mib.org>,
Keith Thompson <ks***@mib.orgwrote:
>Jason8 <ja*********@gmail.comwrites:
>Does anyone know if you can lookup the PID that owns a socket (based
on port number) programmatically? I know most systems have LSOF for
this but I'd like it to be more portable and not call an external
program.

The C language itself doesn't define PIDs, sockets, or port numbers.

Try comp.unix.programmer.
Thank you for your helpful contribution.

Jun 27 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Alexander N. Spitzer | last post by:
If I have a machine with 3 virtual IP addresses (192.168.1.), how can I start 3 instances of the same RMI application (each started with different properties/configs), each listening on the port...
12
by: Don Bruder | last post by:
A week or two ago, I asked here about porting Python to C. Got some good answers (Note 1) but now I've got another question. Actually, more a request for clarification of a topic that both the...
0
by: Cedric | last post by:
I have a WebPage with a usercontrol (webcomponent.dll). With the port 80 on the server, the webpage and the usercontrol works fine If i change the port (18802), the time of loading the usercontrol...
3
by: my-wings | last post by:
I've been reading about how evil Lookup fields in tables are, but I've got to be missing something really basic. I know this subject has been covered before, because I've just spent an hour or two...
3
by: google | last post by:
I have a database with four table. In one of the tables, I use about five lookup fields to get populate their dropdown list. I have read that lookup fields are really bad and may cause problems...
1
by: LurfysMa | last post by:
I am working on an electronic flashcard program. Most of the subjects are simple lists of questions and answers. Those seem to be working. Some of the "subjects" have "categories" of questions. ...
9
by: Cathy | last post by:
I am using a System.Data.SqlClient.SqlConnection to connect to a SQL Server 2005 database. I instantiate the SqlConnection with a connection string... SqlConnection sqlConn = new...
0
by: Zetten | last post by:
I'm trying to develop a page which will grab a few details for the currently logged-in Windows user from the Active Directory controller. I can get the full name of the user from their username...
2
by: r0g | last post by:
Not the visitors IP address, or rdns, indeed they seem to be getting in the way of my googling for the answer despite qualifying my searches with -reverse and -remote_addr No, what I need is a...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.