Como interpretar essa saída do comando 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

Quero desmontar uma unidade, mas não posso.

Então, o que significa cwd, 3r dir e reg?


Ah, cPanel...
jordanm

O man (8) lsof, na seção Saída, explicará tudo isso.
Chromechris #

Respostas:


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 - Descritor de Arquivo

Se você estiver procurando pelo arquivo que está sendo gravado, procure o seguinte sinalizador

# - 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

Isso 3rsignifica que o webalizer possui um descritor número 3 associado ...dns_cache.db, com permissão de leitura.

TYPE - Tipo de arquivo

No Linux, quase tudo são arquivos, mas com tipos diferentes.

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

número de inode no sistema de arquivos

Você pode encontrar detalhes completos na página do manual .


6

Informações sobre o significado das colunas podem ser encontradas na página de manual lsof (8). Vou abordar os que você está perguntando especificamente.

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

Para desmontar a unidade, você provavelmente precisará interromper o servidor da web e interromper o processo do webalizer (já que geralmente é um trabalho em lotes executado a partir do cron).


4

Nesse cenário, eu normalmente uso lsof em combinação com ps para descobrir quem está mantendo o dispositivo ocupado.

Vamos dar um exemplo com um pendrive que foi montado como / media / disk-1

$> 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))

Então, tento descobrir quem está segurando o dispositivo com lsof.

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

E como a coluna 2 é a propriedade pid, podemos obter o nome desse processo com ps.

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

Agora que o bash vem de um terminal que foi aberto em um diretório no dispositivo, então, nesse momento, eu poderia fechar ou matar esse terminal para que o dispositivo estivesse livre novamente.


Atualização Acho que não respondi à pergunta, mas talvez possa ser útil para outra pessoa, então deixo assim mesmo.


3
Bom, mas lsofmostra o nome do processo na primeira coluna. Você não precisa psentender isso. :)
Adambean
Ao utilizar nosso site, você reconhece que leu e compreendeu nossa Política de Cookies e nossa Política de Privacidade.
Licensed under cc by-sa 3.0 with attribution required.