#strace-vs-ebpf
What is the difference between strace and eBPF? When do you use each one?
Что отвечать
`strace` uses ptrace. It stops the process on every syscall, copies the registers into userspace, then hands control back. The overhead is huge (a 10x to 100x slowdown), but it works everywhere. eBPF hooks into tracepoints and kprobes in the kernel and runs its bytecode right there, with no context switch. The overhead is tiny (a few percent), but it needs kernel 4.x or newer and BPF capabilities. In production, reach for eBPF (bpftrace, bcc). On a dev machine, where you just want to understand quickly what one command does, reach for strace.
Что хотят услышать
A senior candidate should: - explain the ptrace overhead. Each syscall means two context switches. - point out that strace on a multi-threaded process with high RPS can serialize everything into one thread and wreck the timings - say that the eBPF verifier guarantees the program terminates and is memory safe, which is why the kernel allows BPF programs to run in production - name the bpftrace one-liners from Brendan Gregg as the canonical set - mention that perf, ftrace, and the BPF Compiler Collection (BCC) are all part of the Linux tracing family, sharing one infrastructure through different entry points
Подводные камни
- ✗ Running strace on a production process with thousands of syscalls per second. The process will grind to a halt.
- ✗ Assuming eBPF can do everything strace does. It cannot. BPF cannot block a syscall, it can only observe.
- ✗ Not knowing that strace follows only the main thread by default. You need `-f` to follow children.
Follow-up
- ? What does `strace -c` do, and why is it the first thing you reach for?
- ? How does the BPF verifier guarantee that a program terminates?
- ? How does a kprobe differ from a tracepoint, and which one is more stable?
Глубина в базе знаний