lsof 快速起步

lsof 快速起步

C.F.AN etony@tom.com

nov 16, 2005

Abstract:

通过大量的示例介绍使用lsof的方法.

文档出处:http://io.expert.com.br/~salvatti/tutoriais/seguranca/site/www.aei.ca/pmatilus/pub/lsof-quickstart.txt


Contents

查看对某个文件的使用情况

查看哪些进程对某个文件进行了调用:

$ lsof /etc/passwd 1

查看对文件系统的使用

/tmp目录被垃圾文件塞满了, 但是, 用ls 又看不到太大文件, 谁干的?

$ lsof /tmp

查找打开,但是不能连接的文件

一个进程打开一个文件, 然后将其设为 unlinked 状态, 则此文件资源仍能被进程使用, 但是其访问路径已经被删除了. 因此, 使用ls不能将其列出. 只有当进程结束时, 才能释放文件占用的资源

查找unlinked 文件, 选项 +L, 作用: 列出打开文件的连接数

$lsof +L

指定连接数的上限 $lsof +L1

同时指定文件系统, 则需要使用 -a(AND) 选项

$ lsof -a +L1 /home

无法卸载

查看谁令mount的分区无法卸载

$ lsof <file_system_name>

查看监听socket

查看网络服务

$ lsof -i

查看某个网络连接

$ lsof -i@aaa.bbb.ccc

$ lsof -iTCP@aaa.bbb.ccc:ftp-data *指定协议*

$ lsof -i4 *指定IP版本*

$ lsof -i6

识别 Netstat 连接

例如: netstat -p -t -n 的输出为:

Proto Recv-Q Send-Q Local Address Foreign Address State

tcp 0 0 218.56.203.246:52634 202.109.72.72:7000 ESTABLISHED

则可以: tony@tony:~$ lsof -iTCP@202.109.72.72:7000

COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME

xchat 4505 tony 12u IPv4 5775 TCP 218.56.203.246:52634->202.109.72.72:afs3-fileserver (ESTABLISHED)

查找针对某个命令打开的文件

使用命令的PID

$ lsof -p <PID>

使用命令名称

$ lsof -c <first_characters_of_command_name_that_interest_you>

$ lsof -c sendmail

查看谁在使用设备文件

$ lsof /dev/hda6

查看某个用户的操作

$ id -u tony

1000

$ lsof -u1000 or $ lsof -utony

$ lsof -u^tony * 则是取反的意思*

更多信息

更多信息参阅 lsof 的联机手册losf(1).

Bibliography

1
http://io.expert.com.br/~salvatti/tutoriais/seguranca/site/www.aei.ca/pmatilus/pub/lsof-quickstart.txt;

About this document ...

lsof 快速起步

This document was generated using the LaTeX2HTML translator Version 2002-2-1 (1.71)

Copyright © 1993, 1994, 1995, 1996, Nikos Drakos, Computer Based Learning Unit, University of Leeds.
Copyright © 1997, 1998, 1999, Ross Moore, Mathematics Department, Macquarie University, Sydney.

The command line arguments were:
latex2html lsof.tex -split 1 -local_icons

The translation was initiated by tony on 2005-12-18

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值