Get process ID from "lxc exec" on host machine

,

It’s reasonably straightforward to translate a host PID into a pidns PID by looking at /proc/PID/status but the reverse isn’t particularly easy.

You may have a PID 7749 in every container on your system. There is a mechanism to translate those PIDs but that involves send a specifically crafted structure (ucred) over a unix socket from within the container to the outside.

In your case, I guess you could get the PID of the container through lxc info, then iterate through /proc to get all the child processes for that container and for those, match them with the PID you’re looking for based on their status file. But this is going to be very inefficient and quite racy.