[Lxc-users] mapping host PID <-> container PID

Gordon Henderson gordon at drogon.net
Thu Apr 28 13:07:19 UTC 2011


On Thu, 28 Apr 2011, Ulli Horlacher wrote:

> Is there a way to get the corresponding host PID for a container PID?
>
> For example: inside the the container the process "init" has always PID 1.
> But what PID has this process in the host process table?
>
> ps aux | grep ... is not what I am looking for, I want more robust solution.

lxc-ps ?

>From Dobrica Pavlinusic's LXC script:

   init_pid=`lxc-ps -C init -o pid | grep "^$name" | cut -d" " -f2-`

So if you're looking for 'init' in a container called pegasus:

   lxc-ps -C init -o pid | grep "^pegasus" | cut -d" " -f2-

Yields 24766 on my system, and a regular ps ax | fgrep init does give:

   24766 ?        Ss     7:55 init [2]

(amongst others)

Gordon




More information about the lxc-users mailing list