PIDについて備忘録的な
色々あるので纏めてみた
task_sturct構造体とPID構造体とPID名前空間がごちゃごちゃにならないようにしないと…
BCCのツールで直接取得
data.e_pid = bpf_get_current_pid_tgid();
上位32ビット TGID
下位32ビット PID
の64ビットを返り値で渡してくれるヘルパー関数
u32に直接渡すと上位32ビットが破棄される
PIDだけ使うなら楽
BCCでtask_struct構造体から取得する
struct task_struct *task;
task = (struct task_struct *)bpf_get_current_task();
data.t_pid = task->tgid;
なるべく多くのデータにアクセス出来るtask_struct構造体からアクセス出来るように…
名前空間とか考えるとこっちがいいと思う
親のPIDを見てみる
struct task_struct *task;
task = (struct task_struct *)bpf_get_current_task();
data.ppid = task->real_parent->tgid;
task_struct構造体には親のtask_struct構造体のポインタを持つのでそれを使う
struct task_struct *task;
task = (struct task_struct *)bpf_get_current_task();
data.ppid = task->real_parent->tgid;
data.ppid2 = task->real_parent->real_parent->tgid;
real_parent型がtask_struct構造体なので、そのまま繋げれば親の親も見れる。
子供もみたい
struct list_head *list = &(task->children);
get_child = list_entry(list,struct task_struct,children);
data.child_pid = get_child->tgid;
container_of(ptr, type, member)がエラーで…
error: cannot call non-static helper function
スタティックじゃないって言われた…
他のツール見て使ってる所なかったからどうなんだろ…←要検証
コンテナ上でのPIDに変換したい…
コンテナ上で見てるPIDも確認出来るようにしたいので、、、
data.h_pid = bpf_get_current_pid_tgid();//ホスト側
if (task->thread_pid->level ==1){
data.c_pid = task->thread_pid->numbers[1].nr;//コンテナ側
}
levelが深くなった際にloopが使えないから探索していくのが難しい…
参考文献