How to find out which port number is being used by a process

I want to find out which port number the process is and filter the results using a keyword.

For example, I can quickly find out which port numbers are being used by "node" js applications.

It didn't work:

netstat tulnap | grep "node"

      

This did not return port numbers:

ps aux | grep node

      

+3


source to share


3 answers


This is how I found the solution:

     ยป lsof -i -P  | grep node
    node      14489 me   12u  IPv4 0x...      0t0    TCP *:4000 (LISTEN)

      



Also, if I knew the port and I was looking for the process name, I would:

     ยป lsof -i :4000
    COMMAND   PID       USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
    node    14489 me   12u  IPv4 0x...      0t0  TCP *:terabase (LISTEN)

      

+4


source


Active internet connections (no servers)

netstat -pnt 

      



Active internet connections (servers only)

netstat -pntl

      

+1


source


What you are doing will also never work as GREP is never guaranteed to provide one, one, or more than 1 result.

But in the context of your particular case, any process is truly unique and has a unique number. So, first you have to do a search to find the process number.

Doing a simple grep will still give you none, none, or multiple process numbers. But you need to find an additional filter so that you get 1 process number.

If you have 1 process number, you can check the port (s) used by that process.

What makes you think "node" is reported in PS? It also cannot be.

-1


source







All Articles