summaryrefslogtreecommitdiff
path: root/libpod/container_top_linux.go
diff options
context:
space:
mode:
authorValentin Rothberg <vrothberg@suse.com>2018-07-19 14:41:58 +0200
committerAtomic Bot <atomic-devel@projectatomic.io>2018-07-19 20:47:52 +0000
commitba1871dac033783ab0329c9b3c9113a34a90992f (patch)
treef0be2944ff09d857306ea42864c7b24ae86ae9bd /libpod/container_top_linux.go
parent98703eb204923f06555605c648fc165a55214520 (diff)
downloadpodman-ba1871dac033783ab0329c9b3c9113a34a90992f.tar.gz
podman-ba1871dac033783ab0329c9b3c9113a34a90992f.tar.bz2
podman-ba1871dac033783ab0329c9b3c9113a34a90992f.zip
podman-top: use containers/psgo
Use github.com/containers/psgo instead of execing `ps (1)`. The psgo library enables a much more flexible interface with respect to which data to be printed (e.g., capabilities, seccomp mode, PID, PCPU, etc.) while the output can be parsed reliably. The library does not use ps (1) but parses /proc and /dev instead. To list the processes of a given container, psgo will join the mount namespace of the given container and extract all data from there. Notice that this commit breaks compatibility with docker-top. Signed-off-by: Valentin Rothberg <vrothberg@suse.com> Closes: #1113 Approved by: rhatdan
Diffstat (limited to 'libpod/container_top_linux.go')
-rw-r--r--libpod/container_top_linux.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/libpod/container_top_linux.go b/libpod/container_top_linux.go
new file mode 100644
index 000000000..450130add
--- /dev/null
+++ b/libpod/container_top_linux.go
@@ -0,0 +1,30 @@
+// +build linux
+
+package libpod
+
+import (
+ "strconv"
+ "strings"
+
+ "github.com/containers/psgo/ps"
+)
+
+// GetContainerPidInformation returns process-related data of all processes in
+// the container. The output data can be controlled via the `descriptors`
+// argument which expects format descriptors and supports all AIXformat
+// descriptors of ps (1) plus some additional ones to for instance inspect the
+// set of effective capabilities. Eeach element in the returned string slice
+// is a tab-separated string.
+//
+// For more details, please refer to github.com/containers/psgo.
+func (c *Container) GetContainerPidInformation(descriptors []string) ([]string, error) {
+ pid := strconv.Itoa(c.state.PID)
+ format := strings.Join(descriptors, ",")
+ return ps.JoinNamespaceAndProcessInfo(pid, format)
+}
+
+// GetContainerPidInformationDescriptors returns a string slice of all supported
+// format descriptors of GetContainerPidInformation.
+func GetContainerPidInformationDescriptors() ([]string, error) {
+ return ps.ListDescriptors(), nil
+}