嵌入式工具——lsof

一个列出当前系统打开文件的工具,在linux环境下,任何事物都已文件的形式存在,因为lsof是一个功能比较强大的工具!

版本:lsof_4.82_src

编译方法:

1. clean
./Configure -clean

2. configure 
LSOF_VERS=31000 LSOF_AR=arm-hisiv300-linux-ar LSOF_CC=arm-hisiv300-linux-gcc LSOF_INCLUDE=/opt/hisi-linux/x86-arm/arm-hisiv300-linux/target/usr/include LSOF_ARCH=arm ./Configure linux


注:LSOF_VERS内核版本号,组合方法见00XCONFIG文档;

全部按回车配置就OK

arm-hisiv300-linux为使用的交叉编译器

3. 修改根目录Makefile
CFGL=    -L./lib -llsof 
to
CFGL=    -L./lib -llsof -static

4. 修改lib/Makefile
AR=     arm-hisiv200-linux-ar ${LIB} ${OBJ}
to
AR=     arm-hisiv200-linux-ar cr ${LIB} ${OBJ} 

5. 编译
make

6. objectfile
lsof


使用方法:

1、查看lsof所有命令 lsof -h/?,显示如下:
lsof 4.82
Defaults in parentheses; comma-separated set (s) items; dash-separated ranges.
  -?|-h list help          -a AND selections (OR)     -b avoid kernel blocks
  -c c  cmd c ^c /c/[bix]  +c w  COMMAND width (9)     
  +d s  dir s files        -d s  select by FD set     +D D  dir D tree *SLOW?*
                           -i select IPv[46] files    -l list UID numbers
  -n no host names         -N select NFS files        -o list file offset
  -O avoid overhead *RISK  -P no port names           -R list paRent PID
  -s list file size        -t terse listing           -T disable TCP/TPI info
  -U select Unix socket    -v list version info       -V verbose search
  +|-w  Warnings (+)       -X skip TCP&UDP* files     -- end option scan
  +f|-f  +filesystem or -file names     +|-f[gG] flaGs 
  -F [f] select fields; -F? for help  
  +|-L [l] list (+) suppress (-) link counts < l (0 = all; default = 0)
                                        +m [m] use|create mount supplement
  +|-M   portMap registration (-)       -o o   o 0t offset digits (8)
  -p s   exclude(^)|select PIDs         -S [t] t second stat timeout (15)
  -T qs TCP/TPI Q,St (s) info
  -g [s] exclude(^)|select and print process group IDs
  -i i   select by IPv[46] address: [46][proto][@host|addr][:svc_list|port_list]
  +|-r [t] repeat every t seconds (15);  + until no files, - forever.
  -s p:s  exclude(^)|select protocol (p = TCP|UDP) states by name(s).
  -u s   exclude(^)|select login|UID set s
  -x [fl] cross over +d|+D File systems or symbolic Links
  names  select named files or files on named file systems


2、常见使用案例
(1)lsof <filename> 
文件被哪些进程打开


(2)lsof <目录>
该目录下的文件被哪些进程打开(注:目录选取不合理显示不出来)


(3)lsof -i<4/6>
显示所有打开socket的进程,括号参数显示ipv4或ipv6的信息


(4)lsof -i tcp/udp:<portnum>
显示该协议端口对应的所有进程


(5)lsof -p <pid,pid> 或者 -c <进程名字或名字部分-c Challenge -c Ch >
显示该进程打开的所有打开文件


(6)lsof -N
显示通过NFS登陆所打开的所有文件


(7)lsof -S 5 or lsof -bw or lsof -n

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值