Closed praf111 closed 7 years ago
That's because exec sessions aren't children of pid 1 in containers, they are their own pid tree.
So if your tool goes up the tree based on PPID (which your output suggests), it won't see the most of the processes.
Ok thanks, then how can i get handle over all the processes inside container using kernel API?
Just iterate through /proc
Actually i am trying to write a system call explicitly for containers, so i need some mechanism to distinguish between tasks of different containers (and also recognize all the tasks of particular container ). so when i use the task list provided by css_set i am not getting all the processes that belong to particular container, so i would like to know any API(in kernel space) provided by kernel so that i can handle over all the processes of particular container. i think iterating over /proc is fine at user level.
So first of all, note that there are absolutely no concept of containers in the Linux kernel, so if you intend to submit upstream code that's aware of "containers", expect to have to rethink your design.
Containers tasks are tied together by a PID namespace. So you'd need to grab hold of the PID namespace for PID 1 in the container and then look at all the other tasks inside that namespace. I'm not sure what the functions inside the kernel are for that though. I've only ever played with the functions that convert PIDs back and forth in there.
Also note that the PID namespace is hierarchical so two processes that are "inside" the container may in fact be in different PID namespaces with one being in a children namespace. That's what happens when you run nested containers or when various software use pid namespaces as a security measure (systemd, chrome, ...).
Closing as this isn't a LXD issue (nor a container issue even) but a question about the PID namespace implementation in the Linux kernel which may be better answered on containers@lists.linuxfoundation.org.
Ok, thank you very much.
The template below is mostly useful for bug reports and support questions. Feel free to remove anything which doesn't apply to you and add more information where it makes sense.
Required information
Issue description
A brief description of what failed or what could be improved.
Steps to reproduce
Information to attach
} output:- pid name 432 bash 456 test