I'm new to eBPf, I want to chang kernel program attached to the same event in user application. So I write the following code:
#!/usr/bin/python
from bcc import BPF
import time
import sys
prog1 = """
int hello(void *ctx) {
bpf_trace_printk("Hello world\\n");
return 0;
}
"""
prog2 = """
int hello(void *ctx) {
bpf_trace_printk("Hello hhh\\n");
return 0;
}
"""
index = 1
while True:
if index == 1:
b = BPF(text=prog1)
index = 2
else:
b = BPF(text=prog2)
index = 1
# attach the program to an event
clone = b.get_syscall_fnname("clone")
b.attach_kprobe(event=clone, fn_name="hello")
line = b.trace_readline(nonblocking=False)
print(line)
sys.stdout.flush()
time.sleep(3)
# b.trace_print()
But the result is not what I expect. It seems that the kernel program doesn't change at all. Any help?