title: how to find which process bind a socket but not listen?
body: <p>When I use nc to listen a port , it shows</p>
  
  <pre><code>nc -l -vv -p 21000
  
  retrying local 0.0.0.0:21000 : Address already in use Can't grab 0.0.0.0:21000 with bind
  </code></pre>
  
  <p>But I can not find which task occupy's this port with tools netstat / ss</p>
  
  <pre><code>netstat -an|grep 21000 
  </code></pre>
  
  <p>;nothing find</p>
  
  <pre><code>ss -a|grep 21000 
  </code></pre>
  
  <p>;nothing find</p>
  
  <p>This port is occupied by my java program, the code is :</p>
  
  <pre><code>public class Test1 {
  
          public static void main(String[] args) throws InterruptedException {
          Socket s = new Socket();
          try {
              s.bind(new InetSocketAddress("127.0.0.1",21000));
          } catch (IOException e) {
              e.printStackTrace();
  
          }
          Thread.sleep(500000000000L);
      }
  }
  </code></pre>
  
  <p>when I bind a socket ,but do not use it with connect or listen. 
  I get into the /proc/[java task id]/fd , find the inode of this socket is "socket:[3073501]" 
  but I can't find the inode or port even in /proc/net/tcp or /proc/net/tcp6</p>
  
  <p>Is there any method to find the process which bind's the socket but does not listen or connect.</p>
  
  <p>Thanks.</p>
  
  <p>I see linux 3.10.0-327 source code. I think the content of the file /proc/net/tcp come from the net/ipv4/tcp_ipv4.c. </p>
  
  <p>in tcp_proc_register method,  </p>
  
  <pre><code>static void *tcp_get_idx(struct seq_file *seq, loff_t pos)      
  {
          void *rc;
          struct tcp_iter_state *st = seq-&gt;private;
  
          st-&gt;state = TCP_SEQ_STATE_LISTENING;
          rc        = listening_get_idx(seq, &amp;pos);
  
          if (!rc) {
                  st-&gt;state = TCP_SEQ_STATE_ESTABLISHED;
                  rc        = established_get_idx(seq, pos);
          }
  
          return rc;
  }
  </code></pre>
  
  <p>It shows only the socks in listening or established from tcp_hashinfo. But tcp_hashinfo has three struct</p>
  
  <pre><code>struct inet_bind_hashbucket     *bhash; 
  struct inet_listen_hashbucket   listening_hash[INET_LHTABLE_SIZE];
  struct inet_ehash_bucket        *ehash;
  </code></pre>
  
  <p>bhash may be used for binding.
  But is does not export in /proc/net/tcp.</p>