【转载】获取更多/proc/fd中有关socket的信息
Q:
Looking in /proc/$mypid/fd/, I see these files
lrwx------ cm_user cm_user Oct : -> /dev/pts/ (deleted)
lrwx------ cm_user cm_user Oct : -> socket:[]
lrwx------ cm_user cm_user Oct : -> socket:[]
lrwx------ cm_user cm_user Oct : -> socket:[]
Because I have access to the code, I know these sockets are tied to TCP connections (one is a connection to port 5672 on some machine, another is a connection to port 3306 on some other machine), but I want to know which socket is tied to which connection. How can I do that?
More generally, how can I ask the OS what is at the other end of the socket?
A:
A good option might be lsof. As man lsof states it is handy for obtaining information about open files such as Internet sockets or Unix Domain sockets.
Using it
At first, get an overview about /proc/$PID/fd/ and the listed socket numbers.
For example, socket:[14240] might interest you.
Then use lsof -i -a -p $PID to print a list of all network files $PID uses.
-iproduces a list of network files belonging to a user or process-alogically combines or AND's given parameters-p $PIDselects info only about your process
A typical output for my browser running with a PID of 2543 might be:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
browser pidi 55u IPv4 0t0 TCP pidi.router.lan:->stackoverflow.com:https (ESTABLISHED)
and more similar lines.
Great! Now take a closer look at the DEVICE column. It matches our previously listed socket from /proc/$PID/fd/!
And thanks to the NAME section we can say what the other end of our socket is.
In a real world run you might get a good amount of output, but just filter or grep for your socket of interest.
I'm pretty sure one could combine all commands, but that should be enough to get you started.
https://unix.stackexchange.com/questions/235979/how-do-i-find-out-more-about-socket-files-in-proc-fd
Q:
I am confused about the output below :
cd /proc/ ; ls -l fd
lrwx------ root root 10月 : -> socket:[]cd /proc/ ; ls -l fd lrwx------
what does socket:[294364529] mean ?
I guess it should be a socket opened by this thread, but what does the number mean ?
How can I find the port or Unix socket path corresponding to this ?
thanks !
A:
Based on your example "2045" is pid number of process and "294364529" is inode number of socket. In Linux sockets use normal file operations so this is why they have inode numbers.
Example: Let assume that I have in system socket with inode number 4654214.
Netstat:
netstat -alep | egrep -i "Inode|4654214"
Proto Recv-Q Send-Q Local Address Foreign Address State User Inode PID/Program name
tcp *: *:* LISTEN root /nc
Lsof:
lsof -i | grep ""
nc root 3u IPv4 0t0 TCP *: (LISTEN)
More raw info (fot tcp):
grep -i "" /proc/net/tcp
: :270F : 0A : : cc2c5f00 -
This is way how you can get useful info about sockets. Additionally look at ss command.
【转载】获取更多/proc/fd中有关socket的信息的更多相关文章
- 【转载】 C#往文件中追加文本内容信息
在C#的文件相关操作中,往已有的文件中追加相关内容信息也是常有的操作,例如我们在写网站日志文件的时候,很多时候是1天的日志存放在一个txt文件中,此时就涉及到往原有文件中追加写入文本内容信息,追加文本 ...
- 【转载】 C#使用Select方法快速获取List集合集合中某个属性的所有值集合
在C#的List集合操作或者数组操作中,有时候我们需要获取到List集合元素中所有的对象的某个属性,然后存放到一个数组集合中,此时就可以使用到List集合以及数组的扩展方法Select方法快速实现获取 ...
- 转载MSDN 在ASP.NET 中执行 URL 重写
转载文章原网址 http://msdn.microsoft.com/zh-cn/library/ms972974.aspx 摘要:介绍如何使用 Microsoft ASP.NET 执行动态 URL 重 ...
- linux中对socket的理解 socket高并发
1.socket是什么? 其实准确的来说,socket并不仅仅用于linux而已,它也应用于TCP/IP中.笼统的来说,socket就是指的“IP地址+端口号”.比如我有一个ssh服务器A,这时候我有 ...
- Java中的Socket的用法
Java中的Socket的用法 Java中的Socket分为普通的Socket和NioSocket. 普通Socket的用法 Java中的 ...
- 【转载】浅谈HTTP中Get与Post的区别
[转载]http://www.cnblogs.com/hyddd/ Http定义了与服务器交互的不同方法,最基本的方法有4种,分别是GET,POST,PUT,DELETE.URL全称是资源描述符,我们 ...
- 在/proc文件系统中增加一个目录hello,并在这个目录中增加一个文件world,文件的内容为hello world
一.题目 编写一个内核模块,在/proc文件系统中增加一个目录hello,并在这个目录中增加一个文件world,文件的内容为hello world.内核版本要求2.6.18 二.实验环境 物理主机:w ...
- 读懂Java中的Socket编程
Socket,又称为套接字,Socket是计算机网络通信的基本的技术之一.如今大多数基于网络的软件,如浏览器,即时通讯工具甚至是P2P下载都是基于Socket实现的.本文会介绍一下基于TCP/IP的S ...
- 读懂Java中的Socket编程(转)
Socket,又称为套接字,Socket是计算机网络通信的基本的技术之一.如今大多数基于网络的软件,如浏览器,即时通讯工具甚至是P2P下载都是基于Socket实现的.本文会介绍一下基于TCP/IP的S ...
随机推荐
- 深入浅出 Java Concurrency (19): 并发容器 part 4 并发队列与Queue简介[转]
Queue是JDK 5以后引入的新的集合类,它属于Java Collections Framework的成员,在Collection集合中和List/Set是同一级别的接口.通常来讲Queue描述的是 ...
- centos7下python3和pycharm安装
1.python3安装 直接到官网下载或在以下地址下载让后解压安装 下载地址:https://www.python.org/ftp/python/ 安装参考博客:https://www.cnblogs ...
- 木卯先生的笔记---Object类
1.简介 Object类是在 java.lang 包下的一个类,它是所有类的父类(也就是所有类都是Object类的子类,如果定义一个类的时候,没有指定继承的类,默认的就是继承Object类),所以Ob ...
- IO流17 --- 对象流操作自定义对象 --- 技术搬运工(尚硅谷)
序列化 @Test public void test14() throws IOException { ObjectOutputStream oos = new ObjectOutputStream( ...
- Spinrg WebFlux中Cookie的读写
WebFLux与WebMvc的差异 WebFlux读写Cookie不像WebMvc那么直接,最主要的原因是WebMvc是基于Servlet规范的,而WebFlux仅仅遵守的是HTTP协议.所以在使用的 ...
- Web调取摄像头拍照
调取摄像头.拍照 <!doctype html> <html lang="en"> <head> <meta charset=" ...
- LINUX查询登录主机的用户工具:w 、who 、users
w.who和users工具,是查询已登录当前主机的用户:另外finger -s 也同样能查询:侧重点不一样:请自己对比着看:毕竟简单,这里只是介绍 : [beinan@localhost ~]$ w ...
- 彻底理解setTimeout()
之前在网上看了很多关于setTimeout的文章,但我感觉都只是点到为止,并没有较深入的去剖析,也可能是我脑袋瓜笨,不容易被点解.后面看了<你不知道的javascript-上卷>一书,决定 ...
- 通过游戏学python 3.6 第一季 第八章 实例项目 猜数字游戏--核心代码--猜测次数--随机函数和屏蔽错误代码--优化代码及注释--简单账号密码登陆--账号的注册查询和密码的找回修改--锁定账号--锁定次数
通过游戏学python 3.6 第一季 第八章 实例项目 猜数字游戏--核心代码--猜测次数--随机函数和屏蔽错误代码--优化代码及注释--简单账号密码登陆--账号的注册查询和密码的找回修改--锁定账 ...
- HTML5中的数据集dataset和自定义属性data-*
在html5中可为所有元素添加一种自定义的属性,这种属性的前缀以data-开头,比如:data-name,目的是为元素提供与页面渲染无关,但与dom元素强相关的属性.添加完自定义属性后我们可以通过元素 ...