Visit the LQ Articles and Editorials section
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 10-12-2008, 09:44 PM   #1
LQ Newbie
Registered: Jun 2008
Posts: 20

Rep: Reputation: 0
Function for finding Which process is using a port


I am trying to find a C library routine/ sys call that would enable me to find which process is using a particular port. For example, lets sasy I want to find out which process(es) is using port# 2000 to send and receive messasges.
I searched online and found that there is a function called lsof that returns values to the shell when called. But how could I do it in a C program, without having to call lsof and write its results into a file, and then scanning it. I am utilizing a TCP connection on ubuntu with gcc 4.2.3

Thanks in advance.
Old 10-12-2008, 11:18 PM   #2
LQ Guru
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

There is no such function in C (or any other language).

The short answer is:
"On Linux, 'lsof' uses '/proc'".

But for the full story, why don't you simply look at the lsof source itself? It's freely available, and very informative. Here's one place you can get it:

'Hope that helps .. PSM



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
Finding Killed Process Harlin Linux - Security 3 11-01-2007 04:04 PM
Finding the startup process swethas Linux - Kernel 4 11-06-2006 04:10 AM
Finding Function always be not responding! Flamenco Mandriva 6 12-29-2004 05:34 AM
Finding process path praj_linux Solaris / OpenSolaris 5 12-21-2004 11:01 AM
Finding function name from address itsme86 Programming 3 07-16-2004 03:16 AM

All times are GMT -5. The time now is 05:55 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration