如何解释lsof命令的输出?


33
root@host [/home2]# lsof /home2
COMMAND     PID     USER   FD   TYPE DEVICE SIZE/OFF     NODE NAME
php        3182 ctxmortg  cwd    DIR   8,17     4096 32858196 /home2/ctxmortg/public_html/hello
php        3182 ctxmortg    3r   REG   8,17    46404 55781766 /home2/ctxmortg/public_html/hello/cache/subprimemortgagemorgage.com/cache-zch-8284-cache.txt
php        3185 ctxmortg  cwd    DIR   8,17     4096 32858196 /home2/ctxmortg/public_html/hello
php        3185 ctxmortg    3r   REG   8,17     4185 35962154 /home2/ctxmortg/public_html/hello/cache/curl/http%3A%2F%2Fimage.yahoo.cn%2Fs%3Fq%3DNudity%26c%3D0%26s%3D%26page%3D277
php        3187 ctxmortg  cwd    DIR   8,17     4096 32858196 /home2/ctxmortg/public_html/hello
php        3187 ctxmortg    3r   REG   8,17    54640 69699731 /home2/ctxmortg/public_html/hello/cache/newdatingfriends.com/cache-zch-1545-cache.txt
php        3188 ctxmortg  cwd    DIR   8,17     4096 32858196 /home2/ctxmortg/public_html/hello
php        3188 ctxmortg    3r   REG   8,17    54640 21557063 /home2/ctxmortg/public_html/hello/cache/customersdeals.com/cache-zch-5715-cache.txt
php        3189 ctxmortg  cwd    DIR   8,17     4096 32858196 /home2/ctxmortg/public_html/hello
php        3189 ctxmortg    3r   REG   8,17     4185 36028071 /home2/ctxmortg/public_html/hello/cache/curl/http%3A%2F%2Fimage.yahoo.cn%2Fs%3Fq%3DVideos%26c%3D0%26s%3D%26page%3D329
php        3200 ctxmortg  cwd    DIR   8,17     4096 32858196 /home2/ctxmortg/public_html/hello
php        3200 ctxmortg    3r   REG   8,17    21036  9155614 /home2/ctxmortg/public_html/hello/cache/indorealestates.com/cache-zch-8562-cache.txt
lsof       3201     root  cwd    DIR   8,17     4096        2 /home2
lsof       3202     root  cwd    DIR   8,17     4096        2 /home2
webalizer 32342 ctxmortg  cwd    DIR   8,17     4096 32890953 /home2/ctxmortg/tmp/webalizer/eyebestdatedotcomauph.ctxmortgagemortgagerefi.com
webalizer 32342 ctxmortg    5uW  REG   8,17    12288 32890954 /home2/ctxmortg/tmp/webalizer/eyebestdatedotcomauph.ctxmortgagemortgagerefi.com/dns_cache.db
webalizer 32360 ctxmortg  cwd    DIR   8,17     4096 32890953 /home2/ctxmortg/tmp/webalizer/eyebestdatedotcomauph.ctxmortgagemortgagerefi.com
webalizer 32360 ctxmortg    5u   REG   8,17    12288 32890954 /home2/ctxmortg/tmp/webalizer/eyebestdatedotcomauph.ctxmortgagemortgagerefi.com/dns_cache.db
webalizer 32361 ctxmortg  cwd    DIR   8,17     4096 32890953 /home2/ctxmortg/tmp/webalizer/eyebestdatedotcomauph.ctxmortgagemortgagerefi.com
webalizer 32361 ctxmortg    5u   REG   8,17    12288 32890954 /home2/ctxmortg/tmp/webalizer/eyebestdatedotcomauph.ctxmortgagemortgagerefi.com/dns_cache.db
webalizer 32362 ctxmortg  cwd    DIR   8,17     4096 32890953 /home2/ctxmortg/tmp/webalizer/eyebestdatedotcomauph.ctxmortgagemortgagerefi.com
webalizer 32362 ctxmortg    5u   REG   8,17    12288 32890954 /home2/ctxmortg/tmp/webalizer/eyebestdatedotcomauph.ctxmortgagemortgagerefi.com/dns_cache.db
webalizer 32363 ctxmortg  cwd    DIR   8,17     4096 32890953 /home2/ctxmortg/tmp/webalizer/eyebestdatedotcomauph.ctxmortgagemortgagerefi.com
webalizer 32363 ctxmortg    5u   REG   8,17    12288 32890954 /home2/ctxmortg/tmp/webalizer/eyebestdatedotcomauph.ctxmortgagemortgagerefi.com/dns_cache.db
webalizer 32364 ctxmortg  cwd    DIR   8,17     4096 32890953 /home2/ctxmortg/tmp/webalizer/eyebestdatedotcomauph.ctxmortgagemortgagerefi.com
webalizer 32364 ctxmortg    5u   REG   8,17    12288 32890954 /home2/ctxmortg/tmp/webalizer/eyebestdatedotcomauph.ctxmortgagemortgagerefi.com/dns_cache.db
webalizer 32365 ctxmortg  cwd    DIR   8,17     4096 32890953 /home2/ctxmortg/tmp/webalizer/eyebestdatedotcomauph.ctxmortgagemortgagerefi.com
webalizer 32365 ctxmortg    5u   REG   8,17    12288 32890954 /home2/ctxmortg/tmp/webalizer/eyebestdatedotcomauph.ctxmortgagemortgagerefi.com/dns_cache.db
webalizer 32366 ctxmortg  cwd    DIR   8,17     4096 32890953 /home2/ctxmortg/tmp/webalizer/eyebestdatedotcomauph.ctxmortgagemortgagerefi.com
webalizer 32366 ctxmortg    5u   REG   8,17    12288 32890954 /home2/ctxmortg/tmp/webalizer/eyebestdatedotcomauph.ctxmortgagemortgagerefi.com/dns_cache.db
webalizer 32367 ctxmortg  cwd    DIR   8,17     4096 32890953 /home2/ctxmortg/tmp/webalizer/eyebestdatedotcomauph.ctxmortgagemortgagerefi.com
webalizer 32367 ctxmortg    5u   REG   8,17    12288 32890954 /home2/ctxmortg/tmp/webalizer/eyebestdatedotcomauph.ctxmortgagemortgagerefi.com/dns_cache.db
webalizer 32368 ctxmortg  cwd    DIR   8,17     4096 32890953 /home2/ctxmortg/tmp/webalizer/eyebestdatedotcomauph.ctxmortgagemortgagerefi.com
webalizer 32368 ctxmortg    5u   REG   8,17    12288 32890954 /home2/ctxmortg/tmp/webalizer/eyebestdatedotcomauph.ctxmortgagemortgagerefi.com/dns_cache.db
webalizer 32369 ctxmortg  cwd    DIR   8,17     4096 32890953 /home2/ctxmortg/tmp/webalizer/eyebestdatedotcomauph.ctxmortgagemortgagerefi.com
webalizer 32369 ctxmortg    5u   REG   8,17    12288 32890954 /home2/ctxmortg/tmp/webalizer/eyebestdatedotcomauph.ctxmortgagemortgagerefi.com/dns_cache.db
bash      32409     root  cwd    DIR   8,17     4096        2 /home2

我想卸载驱动器,但是不能。

那么,cwd,3r dir和reg是什么意思呢?


啊,cPanel...
jordanm

man(8)lsof在“输出”部分将对此进行解释。
chromechris

Answers:


42
COMMAND     PID     USER   FD   TYPE DEVICE SIZE/OFF     NODE NAME
webalizer 32342 ctxmortg    5uW  REG   8,17    12288 32890954 /home2/ctxmortg/tmp/webalizer/eyebestdatedotcomauph.ctxmortgagemortgagerefi.com/dns_cache.db

FD-文件描述符

如果您正在寻找要写入的文件,请寻找以下标志

# - The number in front of flag(s) is the file descriptor number of used by the process to associated with the file
u - File open with Read and Write permission
r - File open with Read permission
w - File open with Write permission
W - File open with Write permission and with Write Lock on entire file
mem - Memory mapped file, usually for share library

因此,3r意味着webalizer具有与关联的描述符编号3 ...dns_cache.db,具有读取权限。

TYPE-文件类型

在Linux中,几乎所有内容都是文件,但类型不同。

REG - REGgular file, file that show up in directory
DIR - Directory

节点

文件系统中的索引节点号

您可以在手册页中找到完整的详细信息。


6

有关各列含义的信息,请参见lsof(8)联机帮助页。我将具体解决您所询问的问题。

cwd => current working directory
3r  => file descriptor 3 opened for reading
DIR => directory
REG => regular file 

为了卸载驱动器,您可能需要停止网络服务器,并终止webalizer进程(因为通常这是从cron运行的批处理作业)。


4

在这种情况下,我通常将lsof与ps结合使用,以找出谁使设备忙碌。

让我们以安装为/ media / disk-1的USB记忆棒为例

$> sudo umount /media/disk-1 
[sudo] password for cj: 
umount: /media/disk-1: device is busy.
        (In some cases useful info about processes that use
         the device is found by lsof(8) or fuser(1))

因此,我然后尝试找出谁拿着lsof握住了设备。

$> lsof | grep disk-1
bash       7822         cj  cwd       DIR       8,33      16384          1 /media/disk-1

而且由于第2列是pid持有的,我们可以用ps获得该进程的名称。

$> ps -A | grep 7822
7822 pts/1    00:00:00 bash

现在,bash来自在设备目录中打开的终端,因此此时我可以关闭或杀死该终端,以使设备再次释放。


更新我不认为我回答了这个问题,但是也许对其他人有帮助,所以我还是不管了。


3
很好,但是lsof在第一列中显示了进程名称。您不需要ps得到那个。:)
Adambean '18
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.