小编Xii*_*Liu的帖子

如何找到哪个进程绑定套接字但不监听?

当我使用nc来监听端口时,它会显示出来

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
Run Code Online (Sandbox Code Playgroud)

但是我无法使用工具netstat/ss找到哪个任务占用了这个端口

netstat -an|grep 21000 
Run Code Online (Sandbox Code Playgroud)

没有找到

ss -a|grep 21000 
Run Code Online (Sandbox Code Playgroud)

没有找到

这个端口被我的java程序占用,代码是:

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);
    }
}
Run Code Online (Sandbox Code Playgroud)

当我绑定一个套接字,但不要与连接或监听一起使用它.我进入/ proc/[java task id]/fd,发现这个套接字的inode是"socket:[3073501]"但我找不到inode或端口,即使在/ proc/net/tcp或/ proc中也是如此/ NET/TCP6

是否有任何方法可以找到绑定套接字但不监听或连接的进程.

谢谢.

我看到linux 3.10.0-327源代码.我认为文件/ proc/net/tcp的内容来自net/ipv4/tcp_ipv4.c.

在tcp_proc_register方法中,

static void *tcp_get_idx(struct seq_file *seq, loff_t pos) …
Run Code Online (Sandbox Code Playgroud)

sockets linux bind

6
推荐指数
1
解决办法
1010
查看次数

标签 统计

bind ×1

linux ×1

sockets ×1