9
"github.com/containers/podman/v5/libpod/define"
12
// GetPodPidInformation returns process-related data of all processes in
13
// the pod. The output data can be controlled via the `descriptors`
14
// argument which expects format descriptors and supports all AIXformat
15
// descriptors of ps (1) plus some additional ones to for instance inspect the
16
// set of effective capabilities. Each element in the returned string slice
17
// is a tab-separated string.
19
// For more details, please refer to github.com/containers/psgo.
20
func (p *Pod) GetPodPidInformation(descriptors []string) ([]string, error) {
21
// Default to 'ps -ef' compatible descriptors
22
if len(strings.Join(descriptors, "")) == 0 {
23
descriptors = []string{"user", "pid", "ppid", "pcpu", "etime", "tty", "time", "args"}
26
jailNames := make([]string, 0)
27
ctrsInPod, err := p.AllContainers()
31
for _, c := range ctrsInPod {
33
err := c.syncContainer()
39
if c.state.State == define.ContainerStateRunning {
40
jailName, err := c.jailName()
42
return nil, fmt.Errorf("getting jail name: %w", err)
44
jailNames = append(jailNames, jailName)
48
// Also support comma-separated input.
49
psDescriptors := []string{}
50
for _, d := range descriptors {
51
for _, s := range strings.Split(d, ",") {
53
psDescriptors = append(psDescriptors, s)
58
// For consistency with pod_top_linux.go, only allow descriptor names
59
for _, d := range psDescriptors {
60
if _, ok := isDescriptor[d]; !ok {
61
return nil, fmt.Errorf("unknown descriptor: %s", d)
67
strings.Join(jailNames, ","),
69
strings.Join(psDescriptors, ","),
72
output, err := execPS(args)
74
return nil, fmt.Errorf("executing ps(1): %w", err)