title: How to query ports are using by one process with knowing its name or pid on mac?
body: <p>I want to query ports are using by one process,I have known the pid of the process using <code>ps aux | grep &lt;name regex of process&gt;</code>,but I don't know how to get the ports being used by it.On linux,we can use <code>netstat -anp | grep &lt;pid&gt;</code>,but the command doesn't work on mac,it throws such hint:</p>
  
  <pre><code>netstat: option requires an argument -- p
  Usage:  netstat [-AaLlnW] [-f address_family | -p protocol]
  netstat [-gilns] [-f address_family]
  netstat -i | -I interface [-w wait] [-abdgRtS]
  netstat -s [-s] [-f address_family | -p protocol] [-w wait]
  netstat -i | -I interface -s [-f address_family | -p protocol]
  netstat -m [-m]
  netstat -r [-Aaln] [-f address_family]
  netstat -rs [-s]
  </code></pre>
  
  <p>Looks like it needs one parameter for <code>-p</code> to specify the types of protocol,but I don't want and don't know the type,then how to solve my question,thanks!</p>
  
  <p><strong>It's a problem on Mac and easy to check,so I wish all the answers can test your solution on your mac machine at first.And maybe the answer is not single,So I'm waiting for your different but useful answers.Thanks for all who pay attention to this question.</strong></p>