Lxc list column for process number?


I try to get the list of the CT, including a colimn with the process number in each CT.
With “lxc info $CT” I can see:
Processes: 3

But with “lxc list” I can not find any config key for the process number to specify with the “-c” option.
I checked on https://github.com/lxc/lxd/blob/master/doc/containers.md with no success.

Any ideas ?

Indeed, there is no key to show the current number of processes in a container. The number of processes is just one of the many datapoints you would need from a container. Ideally, you would want much more insight on what is going on in a container.

You would need a dedicated tool instead, such as sysdig. See more at https://blog.simos.info/how-to-use-sysdig-and-falco-with-lxd-containers/

Are you attempting to just get a list of running processes from each of the running containers? If so, this is a simple hacky way to do just that:

for x in $(lxc list | grep RUNNING | awk -F'|' {'print $2'}); do lxc exec $x -- ps; done;
  PID TTY          TIME CMD
 3873 ?        00:00:00 ps
  PID TTY          TIME CMD
 2282 ?        00:00:00 ps
  PID TTY          TIME CMD
24408 ?        00:00:00 ps
  PID TTY          TIME CMD
 5763 ?        00:00:00 ps
  PID TTY          TIME CMD
21181 ?        00:00:00 ps
  PID TTY          TIME CMD
27492 ?        00:00:00 ps
  PID TTY          TIME CMD
26054 ?        00:00:00 ps
  PID TTY          TIME CMD
 4791 ?        00:00:00 ps
  PID TTY          TIME CMD
 1703 ?        00:00:00 ps
  PID TTY          TIME CMD
13684 ?        00:00:00 ps

Hopefully, that might help? If I misread what you’re attempting, please let me know.

You might want to use the command ps auxf instead of just ps, to get the full process tree of all user processes inside the containers, btw.


  • Andrew

You can also use ‘htop’ displaying the cgroups column, which shows which cgroup is the process running.

Ok thank you all for the alternatives !


It’d be a reasonable thing to add to lxc list as an optional column, feel free to file a bug at https://github.com/lxc/lxd/issues or better yet, send a pull-request for it.

Created https://github.com/lxc/lxd/pull/4142

1 Like