LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices



Reply
 
Search this Thread
Old 10-12-2008, 09:44 PM   #1
raghu2383
LQ Newbie
 
Registered: Jun 2008
Posts: 20

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


Hi,

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
paulsm4
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:

http://freshmeat.net/projects/lsof/

'Hope that helps .. PSM
 
  


Reply

Tags
tcp


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 11:48 PM.

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