Kriss
January 1, 2021, 2:00pm
1
Hi
I have identified from the host a process by its PID. How to easily determine in which container it is running?
I know “ps fauxww”, or even looping each CT+ps -ef + filtering, but I’d prefer something more efficient.
Same question if I have identified a or several process by their user ID. How to identify to which container this user ID belongs to ?
Happy New Year!
stgraber
(Stéphane Graber)
January 1, 2021, 3:23pm
2
You could try to guess from the cgroup in /proc/PID/cgroup
hi-ko
(Heiko Robert)
March 14, 2023, 9:15am
4
would be nice to have such a thing directly available in the lxc command like
lxc pidinfo list <container>
lxc pidinfo getcontainer <pid>
Would it be worth to create a ticket in github?
At the moment I use custom bash functions like
lxc_get_container_pids(){
CONTAINER=$1
find /sys/fs/cgroup/lxc.payload.${CONTAINER}/ -name cgroup.procs -exec cat {} \;
}
lxc_get_container_by_pid(){
PID=$1
cat /proc/${PID}/cgroup|awk -F '/' '{ split($2,a,".");print a[3] }'
}
Maybe related to systemd-cgtop and lxc-top for one or more lxd hosts #822
2 Likes
Bean_Taxi
(Bean Taxi)
July 17, 2024, 2:16pm
5
I’m curious … why
find /sys/fs/cgroup/lxc.payload.${CONTAINER}/ -name cgroup.procs -exec cat {} \
instead of
cat /sys/fs/cgroup/lxc.payload.${CONTAINER}/cgroup.procs
?
I’m sure there’s a reason. I’m just curious what it is. it’s probably interesting
simos
(Simos Xenitellis)
July 17, 2024, 4:04pm
6
You are likely looking for a command like pstree
or atop
that has knowledge of containers and can automatically group them together.
I would rather see a pstree
that has such an option.
pstree
has a -S
to show namespace transitions . Could be possible to request to show the container name.
├─incusd(4568)───systemd(4587,cgroup,ipc,mnt,net,pid,user,uts)─┬─agetty(5049)
│ ├─cron(5039)
│ ├─dbus-daemon(5042)
│ ├─networkd-dispat(5045)
│ ├─rsyslogd(5046)─┬─{rsyslogd}(5050)
│ │ └─{rsyslogd}(5051)
│ ├─systemd-journal(4809)
│ ├─systemd-logind(5047,mnt,uts)
│ ├─systemd-network(4889,mnt)
│ ├─systemd-resolve(4940,mnt)
│ └─systemd-udevd(4860,mnt,uts)