A few months ago cgroup handling in lxc was updated so that if /sys/fs/cgroup/$cgroup/lxc/$container already exists (most often due to another container by the same name under a different lxcpath), then /sys/fs/cgroup/$cgroup/lxc/${container}-N would be used.
lxc-ps was never updated to handle this. Fix that. (Note, the ns cgroup is being special cased there, but I don't really believe ns cgroup works any more.) It would be preferable to rewrite lxc-ps in python or in C, but this at least makes the basic lxc-ps work in the case of multiple containers with the same name. Signed-off-by: Serge Hallyn <serge.hal...@ubuntu.com> --- src/lxc/lxc-ps.in | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/lxc/lxc-ps.in b/src/lxc/lxc-ps.in index 55a05ce..eaf5002 100644 --- a/src/lxc/lxc-ps.in +++ b/src/lxc/lxc-ps.in @@ -17,9 +17,11 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +. @DATADIR@/lxc/lxc.functions + usage() { - echo "usage: $(basename $0) [--lxc | --host | --name NAME] [--] [PS_OPTIONS...]" >&2 + echo "usage: $(basename $0) [-P PATH] [--lxc | --host | --name NAME] [[--] [PS_OPTIONS...]" >&2 } help() { @@ -31,6 +33,7 @@ help() { echo " --host show processes not related to any container, i.e. to the host" >&2 echo " --name NAME show processes in the specified container" >&2 echo " (multiple containers can be separated by commas)" >&2 + echo " -P PATH show container in lxcpath PATH" >&2 echo " PS_OPTIONS ps command options (see \`ps --help')" >&2 } @@ -65,7 +68,7 @@ get_parent_cgroup() # (do not append '/lxc' if the hierarchy contains the 'ns' subsystem) case ",$subsystems," in *,ns,*) parent_cgroup="${mountpoint}${init_cgroup%/}";; - *) parent_cgroup="${mountpoint}${init_cgroup%/}/lxc";; + *) parent_cgroup="${mountpoint}${init_cgroup%/}";; esac break done @@ -83,6 +86,8 @@ while true; do list_container_processes=1; shift;; --host) list_container_processes=-1; shift;; + -P|--lxcpath) + lxc_path=$2; shift 2;; --) shift; break;; *) @@ -111,9 +116,12 @@ for container in ${containers}; do container_field_width=${#container} fi - if [ -f "$parent_cgroup/$container/tasks" ]; then - tasks_files="$tasks_files $parent_cgroup/$container/tasks" - fi + if lxc-info -P $lxc_path -t RUNNING -n z1; then + initpid=`lxc-info -P $lxc_path -p -n $container | awk -F: '{ print $2 }' | awk '{ print $1 }'` + cgroup=`head -n 1 /proc/$initpid/cgroup | awk -F: '{ print $3}'` + if [ -f "$parent_cgroup/$cgroup/tasks" ]; then + tasks_files="$tasks_files $parent_cgroup$cgroup/tasks" + fi done # first file is stdin, the rest are the container tasks -- 1.8.1.2 ------------------------------------------------------------------------------ Learn Graph Databases - Download FREE O'Reilly Book "Graph Databases" is the definitive new guide to graph databases and their applications. This 200-page book is written by three acclaimed leaders in the field. The early access version is available now. Download your free book today! http://p.sf.net/sfu/neotech_d2d_may _______________________________________________ Lxc-devel mailing list Lxc-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/lxc-devel