Closed Timothy-Liuxf closed 1 month ago
If this a feature request, please reply with '/feature'. If this is a question, reply with '/question'. Otherwise please attach logs by following the instructions below, your issue will not be reviewed unless they are added. These logs will help us understand what is going on in your machine.
/question
@Timothy-Liuxf: This is the expected behavior. Internally, WSL uses different PID namespaces for each distros (so each distro has init with pid=1).
What you're most likely seeing in your eBPF program is the PID from the root namespace's perspective, which is different from the one you're seeing in the distro namespace.
@Timothy-Liuxf: This is the expected behavior. Internally, WSL uses different PID namespaces for each distros (so each distro has init with pid=1).
What you're most likely seeing in your eBPF program is the PID from the root namespace's perspective, which is different from the one you're seeing in the distro namespace.
Then how to get the PID of the root namespace in a WSL2 distro (since getpid
cannot)?
By design, you can't do that from within the distribution. There's more info on how this works here: https://www.man7.org/linux/man-pages/man7/pid_namespaces.7.html .
Windows Version
10.0.26100.1742
WSL Version
2.2.4.0
Are you using WSL 1 or WSL 2?
Kernel Version
6.6.36.6-microsoft-standard-WSL2+
Distro Version
Ubuntu 24.04
Other Software
No response
Repro Steps
I compiled the WSL2 kernel manually to get eBPF supported. And I wrote a simple eBPF program to monitor the
getpid
syscall:And I also wrote a program
main.cpp
to triggergetpid
syscall periodically:First, run this trigger program:
And it will print the pid (assume it is
3826
), and compile and run the ebpf prigram:Then mount the tracing filesystem to check the log:
Expected Behavior
It is expected to print:
Actual Behavior
The
pid
returned bybpf_get_current_pid_tgid()
is different fromm_pid
:Diagnostic Logs
WslLogs-2024-10-02_16-46-04.zip