Function for finding Which process is using a port
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
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
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:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.