Reputation: 4285
I want to be able to find out which port number a process is and filtering the results using a keyword.
For example, I may want to quickly find out which port numbers are being used by "node" js apps.
This did not work:
netstat tulnap | grep "node"
This did not return the port numbers:
ps aux | grep node
Upvotes: 6
Views: 33759
Reputation: 4285
This is how I found a 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)
Upvotes: 8
Reputation: 816
What you're doing may also never work since GREP is never guaranteed to deliver either no, one, or more than 1 results.
But, in context of your specific case, any process IS actually unique, and has a unique number. So, you must do your search first to find a process number.
Doing a simple grep will still give you either none, one, or more than one process number. But you'll need to find an additional filter, so that you end up with 1 process number.
If you have 1 process number, you can check port(s) being used by that process.
What makes you think "node" is reported in PS ? It may also not be.
Upvotes: -2
Reputation: 52375
Active Internet connections (w/o servers)
netstat -pnt
Active Internet connections (only servers)
netstat -pntl
Upvotes: 1