lsof 工具

lsof 工具可列出某个Unix 进程所打开文件信息的清单,被打开文件的类型可能包括了:本地文件,目录,网络共享文件,块设备文件,字符设备文件,共享库,管道,软链接,套接字等等.

以下是具体的lsof 操作实例总结:

1,列出所有被打开文件信息

#lsof

2,查看某个被打开文件信息

#lsof /path/to/file

#lsof /path/to/file1 /path/to/file2

3,列出某个目录下的被打开文件

#lsof +D /path

#lsof | grep “/path”

4,列出某个用户下的被打开文件

#lsof -u nobody

#lsof -u nobody,root

5,列出某个进程下的被打开文件

#lsof -c httpd

#lsof -c httpd -c mysqld

6,复合查询(OR)被打开文件信息

#lsof -u nobody -c httpd

7,复合查询(AND)被打开文件信息

#lsof -a -u root -c httpd

8,查看除root之外所有用户的被打开文件

#lsof -u ^root

9,查看具体进程PID的被打开文件

#lsof -p 10101

#lsof -p 10101,10102,10103

10,列出所有网络连接

#lsof -i

11,列出所有网络TCP或者UDP连接

#lsof -i tcp

#lsof -i udp

12,查看具体网络端口信息

#lsof -i :80

#lsof -i tcp:80

#lsof -i udp:53

13,查看具体用户下所有网络连接

#lsof -a -u www -i

14,列出NFS 文件

#lsof -N

15,列出Unix 套接字文件

#lsof -U

16,列出某个特定文件描述符相关联的文件

#lsof -d 2

#lsof -d 0-2

#lsof -d mem

0 1 2 => FD: standard input, output, and error

17,列出所有网络连接关联的PID

#lsof -t -i

#kill -9 `lsof -t -i`  => kill all process use network

18,重复lsof 输出

#lsof -r 1 -a -u www -i


( ! ) Warning: count(): Parameter must be an array or an object that implements Countable in /var/www/vhosts/shan.info/httpdocs/templates/gk_publisher/html/com_k2/templates/default/item.php on line 169
Call Stack
#TimeMemoryFunctionLocation
10.0012411976{main}( ).../index.php:0
20.17364261824Joomla\CMS\Application\SiteApplication->execute( ).../index.php:49
30.17364261824Joomla\CMS\Application\SiteApplication->doExecute( ).../CMSApplication.php:196
40.572411452504Joomla\CMS\Application\SiteApplication->dispatch( ).../SiteApplication.php:233
50.573511476768Joomla\CMS\Component\ComponentHelper::renderComponent( ).../SiteApplication.php:194
60.575411532096Joomla\CMS\Component\ComponentHelper::executeComponent( ).../ComponentHelper.php:377
70.576111559496require_once( '/var/www/vhosts/shan.info/httpdocs/components/com_k2/k2.php' ).../ComponentHelper.php:402
80.591311959128K2ControllerItem->execute( ).../k2.php:64
90.591311959128K2ControllerItem->display( ).../BaseController.php:710
100.633612609832K2ControllerItem->display( ).../item.php:78
110.633612609832K2ControllerItem->display( ).../controller.php:19
120.641612980872Joomla\CMS\Cache\Controller\ViewController->get( ).../BaseController.php:663
130.645613001240K2ViewItem->display( ).../ViewController.php:102
140.773515851632K2ViewItem->display( ).../view.html.php:742
150.773515851632K2ViewItem->loadTemplate( ).../HtmlView.php:230
160.777616024568include( '/var/www/vhosts/shan.info/httpdocs/templates/gk_publisher/html/com_k2/templates/default/item.php' ).../HtmlView.php:701

( ! ) Notice: Only variables should be assigned by reference in /var/www/vhosts/shan.info/httpdocs/templates/gk_publisher/html/com_k2/templates/default/item.php on line 478
Call Stack
#TimeMemoryFunctionLocation
10.0012411976{main}( ).../index.php:0
20.17364261824Joomla\CMS\Application\SiteApplication->execute( ).../index.php:49
30.17364261824Joomla\CMS\Application\SiteApplication->doExecute( ).../CMSApplication.php:196
40.572411452504Joomla\CMS\Application\SiteApplication->dispatch( ).../SiteApplication.php:233
50.573511476768Joomla\CMS\Component\ComponentHelper::renderComponent( ).../SiteApplication.php:194
60.575411532096Joomla\CMS\Component\ComponentHelper::executeComponent( ).../ComponentHelper.php:377
70.576111559496require_once( '/var/www/vhosts/shan.info/httpdocs/components/com_k2/k2.php' ).../ComponentHelper.php:402
80.591311959128K2ControllerItem->execute( ).../k2.php:64
90.591311959128K2ControllerItem->display( ).../BaseController.php:710
100.633612609832K2ControllerItem->display( ).../item.php:78
110.633612609832K2ControllerItem->display( ).../controller.php:19
120.641612980872Joomla\CMS\Cache\Controller\ViewController->get( ).../BaseController.php:663
130.645613001240K2ViewItem->display( ).../ViewController.php:102
140.773515851632K2ViewItem->display( ).../view.html.php:742
150.773515851632K2ViewItem->loadTemplate( ).../HtmlView.php:230
160.777616024568include( '/var/www/vhosts/shan.info/httpdocs/templates/gk_publisher/html/com_k2/templates/default/item.php' ).../HtmlView.php:701
back to top