title: Check which process is using a given port
body: <p>I'm making a simple client-server application in Java. This is how I initialise the listening socket:</p>
  
  <pre><code>private void initSock() {
      try {
          sock = new ServerSocket(port);
      } catch (IOException e) {
          System.err.println("Could not listen on port: "+port+". Isn't the port already in use?");
          System.exit(1);
      }
  }
  </code></pre>
  
  <p>That approach throws likely usefull error message when the port is used - however: Would it be possible to extend the info, like this:</p>
  
  <blockquote>
    <p><em>Could not listen on port <code>xx</code>, it's being used by process <code>blahblah</code> with pid <code>xxx</code>.</em></p>
  </blockquote>
  
  <p>Will Java (and Windows, and eventually other systems) allow me to fetch that info?</p>
  
  <p>I can find this info using command line, but that's really not what I want at this moment.</p>