まず、/procディレクトリに移動して問題を解決します。
ls -al */fd |grep pipe
(上記の「パイプ」を取り除いてみてください。uで詳細を確認できます。)結果は(スナップショットのみ)です。
l-wx------ 1 root root 64 2011-05-14 23:12 17 -> pipe:[39208]
l-wx------ 1 root root 64 2011-05-14 23:12 2 -> pipe:[16245]
lr-x------ 1 root root 64 2011-05-14 23:12 4 -> pipe:[23406]
l-wx------ 1 root root 64 2011-05-14 23:12 8 -> pipe:[23406]
l-wx------ 1 root root 64 2011-05-14 23:12 17 -> pipe:[39532]
l-wx------ 1 root root 64 2011-05-14 23:12 2 -> pipe:[16245]
lr-x------ 1 root root 64 2011-05-14 23:12 4 -> pipe:[23406]
l-wx------ 1 root root 64 2011-05-14 23:12 8 -> pipe:[23406]
l-wx------ 1 root root 64 2011-05-14 23:12 1 -> pipe:[16245]
lr-x------ 1 root root 64 2011-05-14 23:12 16 -> pipe:[40032]
l-wx------ 1 root root 64 2011-05-14 23:12 17 -> pipe:[40032]
l-wx------ 1 root root 64 2011-05-14 23:12 2 -> pipe:[16245]
lr-x------ 1 root root 64 2011-05-14 23:12 4 -> pipe:[23406]
l-wx------ 1 root root 64 2011-05-14 23:12 8 -> pipe:[23406]
l-wx------ 1 tteikhua tteikhua 64 2011-05-14 23:13 1 -> pipe:[16245]
l-wx------ 1 tteikhua tteikhua 64 2011-05-14 23:13 12 -> pipe:[66674]
lr-x------ 1 tteikhua tteikhua 64 2011-05-14 23:13 13 -> pipe:[66674]
l-wx------ 1 root root 64 2011-05-14 23:30 1 -> pipe:[101794]
また、パイプを作成したプロセスを確認したい場合は、たとえば「grep」を削除するだけです。
ここでは、pid=1が6759にパイプfdを持っていることを示しています。
1/fd:
total 0
dr-x------ 2 root root 0 2011-05-14 23:29 .
dr-xr-xr-x 7 root root 0 2011-05-14 22:59 ..
lrwx------ 1 root root 64 2011-05-14 23:29 0 -> /dev/console (deleted)
lrwx------ 1 root root 64 2011-05-14 23:29 1 -> /dev/console (deleted)
lrwx------ 1 root root 64 2011-05-14 23:29 2 -> /dev/console (deleted)
lr-x------ 1 root root 64 2011-05-14 23:29 3 -> pipe:[6759]
そして、上記をfs / pipe.c(これらを出力するLinuxカーネルソース)までさかのぼってトレースします。
/*
* pipefs_dname() is called from d_path().
*/
static char *pipefs_dname(struct dentry *dentry, char *buffer, int buflen)
{
return dynamic_dname(dentry, buffer, buflen, "pipe:[%lu]",
dentry->d_inode->i_ino);
}
static const struct dentry_operations pipefs_dentry_operations = {
.d_dname = pipefs_dname,
};
そしてfs/dcache.cを読む:
char *d_path(const struct path *path, char *buf, int buflen)
{
if (path->dentry->d_op && path->dentry->d_op->d_dname)
return path->dentry->d_op->d_dname(path->dentry, buf, buflen);
and since d_path() is an exported symbol,
EXPORT_SYMBOL(d_path);
どこからでも呼び出すことができ、パスに関する情報を取得できるはずです。パイプの場合は、対応するpipefs_dname()が呼び出されます。ファイルシステムに依存します。
./fs/pipe.c:
.d_dname = pipefs_dname,
inode.cを読み取ります:init_inode_always()とuは、i_pipeがNULLに設定されていることを確認できます。iノードがPIPEの場合のみnullではありません。
したがって、uは常にすべてのプロセスをループして、開いているファイル記述子を取得でき、iノードのi_pipeがNULL以外に設定されている場合、その値がパイプのiノード番号であることがわかります。
そのようなコードはカーネルソースに存在するとは思わない(したがって、それを探す必要はない-私はすでに試した)ユーザースペースでそれを行う方がはるかに効率的で安全である(「ls-al」コマンドのように)前に説明した)次にカーネル内-一般的にカーネルが小さいほどセキュリティバグが少なくなり、安定性などが向上します。