我有寫入 trace_pipe 檔案的 BPF 程式,即使程式正確執行,我也無法從該檔案中讀取資料。
每當我嘗試時cat /sys/kernel/debug/tracing/trace_pipe,該程序都會卡住,并且沒有任何內容顯示為輸出。

我已經通過運行手動安裝了 debugfs:mount -t debugfs none /sys/kernel/debug
當我嘗試 cat、tail、vi 或以某種方式讀取此檔案的內容時,結果是相同的。
即使在我掛載 debugfs 之后,“trace_pipe”檔案也無法讀取,所以我認為這與我的 BPF 代碼執行無關。
這個檔案根本不可讀,我想了解我應該怎么做才能讀取它。
我可以確認 debugfs 已正確安裝,并且該檔案確實存在:


我很感激有關如何閱讀此檔案的任何提示。
uj5u.com熱心網友回復:
所以這只是你的 eBPF 程式中的一個錯誤。從您的鏈接:
int my_pid = 0;
SEC("tp/syscalls/sys_enter_write")
int handle_tp(void *ctx)
{
int pid = bpf_get_current_pid_tgid() >> 32;
if (pid != my_pid)
return 0;
bpf_printk("BPF triggered from PID %d.\n", pid);
return 0;
}
擁有if (pid != my_pid) return 0;,my_pid = 0意味著你每次收集的 PID 為非 0 時退出 - 這幾乎是所有時間。因此,您的程式提前退出,您沒有機會執行對跟蹤管道的呼叫bpf_printk()并將資料發送到跟蹤管道。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/485460.html
上一篇:一行檔案中的字串
