8
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

lsofコマンド

Last updated at Posted at 2015-08-20

機能

lsofコマンドはファイルやポートを開いているプロセス情報を表示します。

使用する機会

・あるファイルを開いているプロセス情報を表示したい時 ・あるポートを開いているプロセスを表示したい時 ・特定のユーザが開いているファイルを表示したい時

書式

lsof [オプション]

使い方

```:secureを開いているプロセスを表示

#lsof /var/log/secure

COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
rsyslogd 1035 root 4w REG 253,0 2486 792351 /var/log/secure



```:ポートをオープンにしているプロセス
#lsof -i:80,443


COMMAND   PID   USER   FD   TYPE   DEVICE SIZE/OFF NODE NAME
httpd   13583   root    4u  IPv6 11754903      0t0  TCP *:http (LISTEN)
httpd   13583   root    6u  IPv6 11754907      0t0  TCP *:https (LISTEN)
httpd   20569 apache    4u  IPv6 11754903      0t0  TCP *:http (LISTEN)
httpd   20569 apache    6u  IPv6 11754907      0t0  TCP *:https (LISTEN)
httpd   21696 apache    4u  IPv6 11754903      0t0  TCP *:http (LISTEN)
httpd   21696 apache    6u  IPv6 11754907      0t0  TCP *:https (LISTEN)
httpd   21700 apache    4u  IPv6 11754903      0t0  TCP *:http (LISTEN)
httpd   21700 apache    6u  IPv6 11754907      0t0  TCP *:https (LISTEN)
httpd   21705 apache    4u  IPv6 11754903      0t0  TCP *:http (LISTEN)
httpd   21705 apache    6u  IPv6 11754907      0t0  TCP *:https (LISTEN)
httpd   24910 apache    4u  IPv6 11754903      0t0  TCP *:http (LISTEN)
httpd   24910 apache    6u  IPv6 11754907      0t0  TCP *:https (LISTEN)
httpd   24911 apache    4u  IPv6 11754903      0t0  TCP *:http (LISTEN)
httpd   24911 apache    6u  IPv6 11754907      0t0  TCP *:https (LISTEN)
httpd   24917 apache    4u  IPv6 11754903      0t0  TCP *:http (LISTEN)
httpd   24917 apache    6u  IPv6 11754907      0t0  TCP *:https (LISTEN)
httpd   25115 apache    4u  IPv6 11754903      0t0  TCP *:http (LISTEN)
httpd   25115 apache    6u  IPv6 11754907      0t0  TCP *:https (LISTEN)
httpd   26244 apache    4u  IPv6 11754903      0t0  TCP *:http (LISTEN)
httpd   26244 apache    6u  IPv6 11754907      0t0  TCP *:https (LISTEN)
httpd   26515 apache    4u  IPv6 11754903      0t0  TCP *:http (LISTEN)
httpd   26515 apache    6u  IPv6 11754907      0t0  TCP *:https (LISTEN)
httpd   26521 apache    4u  IPv6 11754903      0t0  TCP *:http (LISTEN)
httpd   26521 apache    6u  IPv6 11754907      0t0  TCP *:https (LISTEN)
httpd   26840 apache    4u  IPv6 11754903      0t0  TCP *:http (LISTEN)
httpd   26840 apache    6u  IPv6 11754907      0t0  TCP *:https (LISTEN)
httpd   27369 apache    4u  IPv6 11754903      0t0  TCP *:http (LISTEN)
httpd   27369 apache    6u  IPv6 11754907      0t0  TCP *:https (LISTEN)
httpd   27371 apache    4u  IPv6 11754903      0t0  TCP *:http (LISTEN)
httpd   27371 apache    6u  IPv6 11754907      0t0  TCP *:https (LISTEN)
httpd   27855 apache    4u  IPv6 11754903      0t0  TCP *:http (LISTEN)
httpd   27855 apache    6u  IPv6 11754907      0t0  TCP *:https (LISTEN)
httpd   27856 apache    4u  IPv6 11754903      0t0  TCP *:http (LISTEN)
httpd   27856 apache    6u  IPv6 11754907      0t0  TCP *:https (LISTEN)
httpd   28738 apache    4u  IPv6 11754903      0t0  TCP *:http (LISTEN)
httpd   28738 apache    6u  IPv6 11754907      0t0  TCP *:https (LISTEN)
httpd   28923 apache    4u  IPv6 11754903      0t0  TCP *:http (LISTEN)
httpd   28923 apache    6u  IPv6 11754907      0t0  TCP *:https (LISTEN)
httpd   28945 apache    4u  IPv6 11754903      0t0  TCP *:http (LISTEN)
httpd   28945 apache    6u  IPv6 11754907      0t0  TCP *:https (LISTEN)
httpd   30270 apache    4u  IPv6 11754903      0t0  TCP *:http (LISTEN)
httpd   30270 apache    6u  IPv6 11754907      0t0  TCP *:https (LISTEN)
ユーザが開いているファイルを表示
#lsof -u username


lsof -u username
COMMAND   PID      USER   FD   TYPE             DEVICE  SIZE/OFF   NODE NAME
sshd    30766 username  cwd    DIR              202,1      4096      2 /
sshd    30766 username  rtd    DIR              202,1      4096      2 /
sshd    30766 username  txt    REG              202,1    617128 404007 
sshd    30766 username    6r  FIFO                0,8       0t0 123655 pipe
sshd    30766 username    7w  FIFO                0,8       0t0 123655 pipe
sshd    30766 username    8u   CHR                5,2       0t0   6143 /dev/ptmx
sshd    30766 username   10u   CHR                5,2       0t0   6143 /dev/ptmx
sshd    30766 username   11u   CHR                5,2       0t0   6143 /dev/ptmx
bash    30767 username  cwd    DIR              202,1      4096      2 /
bash    30767 username  rtd    DIR              202,1      4096      2 /
bash    30767 username  txt    REG              202,1    898032 396531 /bin/bash
bash    30767 username  mem    REG              202,1     58288 396478 /lib64/libnss_files-2.17.so
bash    30767 username  mem    REG              202,1 106065056 396471 /usr/lib/locale/locale-archive
bash    30767 username  mem    REG              202,1   2107600 396454 /lib64/libc-2.17.so
bash    30767 username  mem    REG              202,1     19512 396461 /lib64/libdl-2.17.so
bash    30767 username  mem    REG              202,1    135616 396516 /lib64/libtinfo.so.5.7
bash    30767 username  mem    REG              202,1    160240 396446 /lib64/ld-2.17.so
bash    30767 username  mem    REG              202,1     26254   1568 /usr/lib64/gconv/gconv-modules.cache
bash    30767 username    0u   CHR              136,0       0t0      3 /dev/pts/0
bash    30767 username    1u   CHR              136,0       0t0      3 /dev/pts/0
bash    30767 username    2u   CHR              136,0       0t0      3 /dev/pts/0
bash    30767 username  255u   CHR              136,0       0t0      3 /dev/pts/0
8
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?