Review your favorite Linux distribution.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 06-28-2005, 10:50 AM   #1
LQ Newbie
Registered: Sep 2004
Posts: 2

Rep: Reputation: 0
Process ID of a socket


I'm trying to write a program which will dyanmically open the firewall for ports open by a specific program (using the libipq library).

for this i need a way to figure out the process id, user id which has created the specific listening socket for a given port (like lsof does). i tried to go through the lsof code but it seems too complicated + since lsof is not gpl i dont have a clear idea what effect it will have on the program that i make (which i plan to make gpl). i realise that i could call lsof from my code but i feel it would give put too much overhead in the process.

can anyone give me some idea as to what i need? this is really my first real linux program so i dont have much of a idea of where to look (google didnt help).

Old 06-28-2005, 11:59 AM   #2
Senior Member
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Try the sources of "netstat" instead of lsof. It's probably simpler and also GPL.

Example: netstat -plan
gives all connected and listening sockets (tcp, udp, and filesy sockets) including PID, and process name. (when not run as root, it will give you this info only for the processes of the user running netstat, but there's no way around that anyway)

"netstat" is (on debian) part of the "net-tools" package. One place to get the sources:

Last edited by Hko; 06-28-2005 at 12:01 PM.
Old 06-28-2005, 11:13 PM   #3
LQ Newbie
Registered: Sep 2004
Posts: 2

Original Poster
Rep: Reputation: 0
many thanks. i'll go through the code.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Unable to connect to UNIX socket /tmp/.esd/socket error while using grip dr_zayus69 Linux - Software 4 08-23-2005 08:28 PM
Socket File Descriptors for a process MadCoder77 Linux - Networking 0 05-26-2005 05:19 PM
using a socket decriptor opened by anoter process sudheernair Programming 6 04-19-2004 11:20 AM
using a socket descriptor opened by another process sudheernair Programming 0 04-16-2004 07:29 AM
share socket between two process Vikash Singh Linux - Networking 0 10-10-2003 08:21 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:41 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration