通过大量的示例介绍使用lsof的方法.
查看对某个文档的使用情况
  查看哪些进程对某个文档进行了调用:
  $ lsof /etc/passwd
1

查看对文档系统的使用
  /tmp目录被垃圾文档塞满了, 但是, 用ls 又看不到太大文档, 谁干的?
  $ lsof /tmp
查找打开,但是不能连接的文档
  一个进程打开一个文档, 然后将其设为 unlinked 状态, 则此文档资源仍能被进程使用, 但是其访问路径已被删除了. 因此, 使用ls不能将其列出. 只有当进程结束时, 才能释放文档占用的资源
  查找unlinked 文档, 选项 L, 作用: 列出打开文档的连接数
  $lsof L
  指定连接数的上限 $lsof L1
  同时指定文档系统, 则需要使用 -a(AND) 选项
  $ lsof -a L1 /home
无法卸载
  查看谁令mount的分区无法卸载
  $ lsof
查看监听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
  使用命令名称
  $ lsof -c
  $ 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


本文来自ChinaUnix博客,假如查看原文请点:http://blog.chinaunix.net/u1/45170/showart_485850.html