lsfd - ファイルディスクリプターの一覧表示
lsfd [option]
lsfd は Linux システム上において、 lsof(8) を最新のものに置き換えるためのものである。 lsof とは違って lsfd は Linux カーネルに特化している。 Linux の特定機能として名前空間などをサポートし、 しかもより簡単なコードにより実装されている。 lsfd は lsof の一時的な置き換えではない。 コマンドラインインターフェースや出力フォーマットに違いがある。
lsfd では出力フォーマットやフィルタリングのために libsmartcols を利用している。 出力フォーマットのカスタマイズについては --output オプションの説明を、 またフィルタリングについては --filter オプションを参照のこと。
-l, --threads
スレッドレベルを一覧表示する。
-J, --json
出力を JSON 書式にする。
-n, --noheadings
ヘッダーを表示しない。
-o, --output list
どのカラムに出力するかを指定する。 利用可能なカラムの詳細は 出力カラム のセクションを参照のこと。
+list という形式 (たとえば lsfd -o +DELETED) を指定すれば、 デフォルトのカラム出力を拡張することができる。
-r, --raw
未加工のままの書式を用いる。
--notruncate
カラム内のテキストを切り詰めない。
-p, --pid pids
指定されたプロセスについての情報のみを収集する。 pids は pid のリストである。 区切り文字にはカンマまたはホワイトスペースを用いる。 このオプションは pidof(1) において用いることができる。 フィルター例 参照。
Both -Q option with an expression including PID, e.g. -Q (PID == 1), and -p option, e.g. -p 1, may print the same output but using -p option is much more efficient because -p option works at a much earlier stage of processing than the -Q option.
-Q, --filter expr
expr により表される条件に一致したファイルのみを表示する。 フィルター例 参照。
-C, --counter label:filter_expr
--summary の出力に用いられるカスタムカウンターを定義する。 lsfd は label というカウンターを作り出す。 情報収集の際に lsfd は filter_expr に一致するファイルをカウントして、 label というカウンターにそのカウント数を保存する。 lsfd はカウントする前に --filter オプションにより定義されたフィルターを適用する。 つまりフィルターによって除外されたファイルはカウントされない。
See FILTER EXPRESSION about filter_expr. label should not include { nor :. You can define multiple counters by specifying this option multiple times.
カウンター例 も参照のこと。
--summary[=when]
このオプションは、 概要の行の出力を制御する。 オプション引数である when に指定できるのは、 only、 append、 never のいずれかである。 when 引数が省略された場合、 デフォルト値は only である。
The summary reports counters. A counter consists of a label and an integer value. --counter is the option for defining a counter. If a user defines no counter, lsfd uses the definitions of pre-defined built-in counters (default counters) to make the summary output.
CAUTION: Using --summary and --json may make the output broken. Only combining --summary=only and --json is valid.
--debug-filter
Dump the internal data structure for the filter and exit. This is useful only for lsfd developers.
--dump-counters
Dump the definition of counters used in --summary output.
-h, --help
ヘルプを表示して終了する。
-V, --version
バージョンを表示して終了する。
各カラムにはタイプがある。 タイプは < と > によって囲まれる。
CAUTION: The names and types of columns are not stable yet. They may be changed in the future releases.
ASSOC <string>
Association between file and process.
BLKDRV <string>
Block device driver name resolved by /proc/devices.
CHRDRV <string>
Character device driver name resolved by /proc/devices.
COMMAND <string>
Command of the process opening the file.
DELETED <boolean>
Reachability from the file system.
DEV <string>
ID of the device containing the file.
DEVTYPE <string>
Device type (blk, char, or nodev).
FD <number>
File descriptor for the file.
FLAGS <string>
Flags specified when opening the file.
FUID <number>
User ID number of the file’s owner.
INODE <number>
i ノード番号。
KTHREAD <boolean>
Whether the process is a kernel thread or not.
MAJ:MIN <string>
Device ID for special, or ID of device containing file.
MAPLEN <number>
ファイルマッピング (ページ内) の長さ。
MISCDEV <string>
Misc character device name resolved by /proc/misc.
MNTID <number>
マウント ID。
MODE <string>
アクセスモード (rwx)。
NAME <string>
ファイル名。
NLINK <number>
リンク数。
OWNER <string>
ファイル所有者。
PARTITION <string>
/proc/partition によって解決されたブロックデバイス名。
PID <number>
ファイルを開いているプロセスのプロセス ID。
POS <number>
ファイル位置。
PROTONAME <string>
プロトコル名。
RDEV <string>
デバイス ID (特殊ファイルの場合)。
SIZE <number>
ファイルサイズ。
SOURCE <string>
そのファイルを含むファイルシステム、パーティション、デバイス。
TID <number>
ファイルを開いているプロセスのスレッド ID。
TYPE <string>
ファイルタイプ。
UID <number>
ユーザー ID 番号。
USER <string>
プロセスのユーザー。
lsfd evaluates the expression passed to --filter option every time before printing a file line. lsfd prints the line only if the result of evaluation is true.
An expression consists of column names, literals and, operators like:
DELETED
, (PID == 1)
,
(NAME == "/etc/passwd")
,
(PID == 1) && DELETED
. DELETED
,
PID
, and NAME
are column names in the example.
1
and "/etc/passwd" are literals. ==
and
&&
are operators.
Before evaluation, lsfd substitutes column names in
the given expression with actual column values in the line. There are
three different data types: boolean, string, and
number. For columns with a boolean type, the value can
be stand-alone. For string and number values, the
value must be an operand of an operator, for example,
(PID == 1)
. See the "OUTPUT COLUMNS" about the types of
columns.
Literal is for representing a value directly. See BOOLLIT, STRLIT, and NUMLIT. Different data types have different literal syntax.
An operator works with one or two operand(s). An operator has an expectation about the data type(s) of its operands. Giving an unexpected data type to an operator causes a syntax error.
Operators taking two operands are and, or, eq, ne, le, lt, ge, gt, =~, !~. Alphabetically named operators have C-language flavored aliases: &&, ||, ==, !=, <, ⇐, >=, and >.
! はオペランドを 1 つ取る唯一のオペレーターである。
eq, ne, およびそのエイリアスは、 オペランドとして同一データタイプを指定する。 これらのオペレーターを用いると boolean を返す。
and, or, not とそのエイリアスは、 オペランドとして bool データタイプを指定する。 これらのオペレーターを用いると boolean を返す。
lt, le, gt, ge, and their aliases expect operands have number data types. Applying these operators return a boolean.
=~ is for regular expression matching; if a string at the right side matches a regular expression at the left side, the result is true. The right side operand must be a string literal. See STRLIT about the syntax.
!~ is a short-hand version of not (STR =~ PAT)
;
it inverts the result of =~.
現時点の実装においては、 オペレーターの優先順位を定義していない。 したがって表現式の中に 3 つ以上のオペレーターを用いる場合は、 明示的に ( と ) を用いて、 表現式をグルーピングすること。
About number typed values, the filter engine supports only non-negative integers.
EXPR
BOOLEXP
BOOLEXP0
COLUMN <boolean> | BOOLLIT | ( BOOLEXP )
BOOLEXP
BOOLEXP0 | BOOLOP1 | BOOLOP2 | BOOLOP2BL | BOOLOP2CMP | BOOLOP2REG
COLUMN
[_A-Za-z][-_:A-Za-z0-9]*
BOOLOP1
! BOOLEXP0 | not BOOLEXP0
STREXP
COLUMN <string> | STRLIT
NUMEXP
COLUMN <number> | NUMLIT
BOOLLIT
true | false
CHARS
( [^\] | \\ | \' | \" )*
STRLIT
' CHARS ' | " CHARS "
NUMLIT
[1-9][0-9]* | 0
BOOLOP2
STREXP OP2 STREXP | NUMEXP OP2 NUMEXP | BOOLEXP0 OP2 BOOLEXP0
OP2
== | eq | != | ne
BOOLOP2BL
BOOLEXP0 OP2BL BOOLEXP0
OP2BL
&& | and | || | or
BOOLOP2CMP
NUMEXP OP2CMP NUMEXP
OP2CMP
< | lt | <= | le | > | gt | >= | ge
BOOLOP2REG
STREXP OP2REG STRLIT
OP2REG
=~ | !~
lsfd にはフィルタリングに関するオプションがある。 たいていの場合に知っておくべきなのは -Q (または --filter) オプションである。 -o (または --output) オプションと組み合わせれば、 出力結果をカスタマイズすることができる。
PID 1 と PID 2 のプロセスに関連するファイルを一覧表示する。
# lsfd -Q '(PID == 1) or (PID == 2)'
同じことを別の記法により行う。
# lsfd -Q '(PID == 1) || (PID == 2)'
同じことをより効果的に行う。
# lsfd --pid 1,2
カンマではなくホワイトスペースを用いることができる。
# lsfd --pid '1 2'
"firefox" に関連するファイルを一覧するために pidof(1) を利用する。
# lsfd --pid "$(pidof firefox)"
PID 1 プロセスによって開かれた最初のファイルディスクリプターを一覧表示する。
# lsfd -Q '(PID == 1) と (FD == 1)'
同じことを別の記法により行う。
# lsfd -Q '(PID == 1) && (FD == 1)'
実行中の実行ファイルをすべて一覧表示する。
# lsfd -Q 'ASSOC == "exe"'
同じことを別の記法により行う。
# lsfd -Q 'ASSOC eq "exe"'
同じことを、 ファイル名表示のみとする。
# lsfd -o NAME -Q 'ASSOC eq "exe"' | sort -u
プロセスに関連した、 削除ファイルを一覧表示する。
# lsfd -Q 'DELETED'
通常ファイル以外を一覧表示する。
# lsfd -Q 'TYPE != "REG"'
ブロックデバイスを一覧表示する。
# lsfd -Q 'DEVTYPE == "blk"'
上と同様であり、さらに TYPE カラムを含める。
# lsfd -Q 'TYPE == "BLK"'
ファイル名に "dconf" ディレクトリを含んだファイルを一覧表示する。
# lsfd -Q 'NAME =~ ".\*/dconf/.*"'
QEMU 仮想マシン内で開いているファイルを一覧表示する。
# lsfd -Q '(COMMAND =~ ".\*qemu.*") and (FD >= 0)'
カーネルスレッドに関連づいたファイルを隠す。
# lsfd -Q '!KTHREAD'
netlink ソケットディスクリプターと unix ソケットディスクリプターそれぞれの数表示する。
# lsfd --summary=only \ -C 'netlink sockets':'(NAME =~ "NETLINK:.*")' \ -C 'unix sockets':'(NAME =~ "UNIX:.*")' VALUE COUNTER 57 netlink sockets 1552 unix sockets
同様のことを行うが、 ただし JSON 書式での出力とする。
# lsfd --summary=only --json \ -C 'netlink sockets':'(NAME =~ "NETLINK:.*")' \ -C 'unix sockets':'(NAME =~ "UNIX:.*")' { "lsfd-summary": [ { "value": 15, "counter": "netlink sockets" },{ "value": 798, "counter": "unix sockets" } ] }
lsfd コマンドは v2.38 から util-linux パッケージの一部となった。
lsof(8) pidof(1) proc(5)
バグ報告は、 以下にある issue トラッカーを利用すること。 <https://github.com/util-linux/util-linux/issues>.
lsfd コマンドは util-linux パッケージの一部であり、 以下からダウンロードできる。 Linux Kernel Archive <https://www.kernel.org/pub/linux/utils/util-linux/>.