9
"github.com/containers/podman/v5/libpod/define"
10
"github.com/containers/podman/v5/pkg/rootless"
11
"github.com/containers/psgo"
14
// GetPodPidInformation returns process-related data of all processes in
15
// the pod. The output data can be controlled via the `descriptors`
16
// argument which expects format descriptors and supports all AIXformat
17
// descriptors of ps (1) plus some additional ones to for instance inspect the
18
// set of effective capabilities. Each element in the returned string slice
19
// is a tab-separated string.
21
// For more details, please refer to github.com/containers/psgo.
22
func (p *Pod) GetPodPidInformation(descriptors []string) ([]string, error) {
26
pids := make([]string, 0)
27
ctrsInPod, err := p.allContainers()
31
for _, c := range ctrsInPod {
34
if err := c.syncContainer(); err != nil {
38
if c.state.State == define.ContainerStateRunning {
39
pid := strconv.Itoa(c.state.PID)
40
pids = append(pids, pid)
45
// Also support comma-separated input.
46
psgoDescriptors := []string{}
47
for _, d := range descriptors {
48
for _, s := range strings.Split(d, ",") {
50
psgoDescriptors = append(psgoDescriptors, s)
55
// NOTE: psgo returns a [][]string to give users the ability to apply
56
// filters on the data. We need to change the API here to return
57
// a [][]string if we want to make use of filtering.
58
opts := psgo.JoinNamespaceOpts{FillMappings: rootless.IsRootless()}
59
output, err := psgo.JoinNamespaceAndProcessInfoByPidsWithOptions(pids, psgoDescriptors, &opts)
64
for _, out := range output {
65
res = append(res, strings.Join(out, "\t"))