how to Find the port number according to PID
The following command can be used to find out which process is listening on a particular port:
netstat -ltnp | grep -w ':8011'
How can we do the opposite, find the port number according to PID number?
lsof
is more appropriate for this:
sudo lsof -i -a -p PID
replacing PID
as appropriate.
According to netstat manual :
This program is mostly obsolete. Replacement for netstat is ss.
So let’s use ss with its -p option then pipe to grep the desired pid.