Files
syscall_monitor/hello.py
MarceloZoeng 81a8573e51
All checks were successful
CI / lint-and-build (push) Successful in 2m35s
CD / deploy (push) Successful in 1m6s
添加测试功能:TCP 写入服务端、单次发送客户端、压力测试客户端、kprobe Hello World基础验证
2026-06-15 20:23:14 +08:00

22 lines
578 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""基础验证eBPF kprobe Hello World 程序(实验大纲 基础验证部分)"""
from bcc import BPF
prog = """
int hello(void *ctx) {
bpf_trace_printk("Hello, World!\\n");
return 0;
}
"""
b = BPF(text=prog)
execve_function = b.get_syscall_fnname("execve")
b.attach_kprobe(event=execve_function, fn_name="hello")
print("%-18s %-16s %-6s %s" % ("TIME(s)", "COMM", "PID", "MESSAGE"))
while True:
try:
task, pid, cpu, flags, ts, msg = b.trace_fields()
except ValueError:
continue
print("%-18.9f %-16s %-6d %s" % (ts, task, pid, msg))