mirror of
https://github.com/containers/podman.git
synced 2025-12-03 19:59:39 +08:00
Vendor changes to psgo
Signed-off-by: haircommander <pehunt@redhat.com> Closes: #1298 Approved by: mheon
This commit is contained in:
committed by
Atomic Bot
parent
c32074fa4f
commit
f11020702d
19
vendor/github.com/containers/psgo/README.md
generated
vendored
19
vendor/github.com/containers/psgo/README.md
generated
vendored
@@ -10,9 +10,15 @@ This library aims to make things a bit more comfortable, especially for containe
|
||||
- `psgo.ProcessInfo(descriptors []string) ([][]string, error)`
|
||||
- ProcessInfo returns the process information of all processes in the current mount namespace. The input descriptors must be a slice of supported AIX format descriptors in the normal form or in the code form, if supported. If the input descriptor slice is empty, the `psgo.DefaultDescriptors` are used. The return value contains the string slice of process data, one per process.
|
||||
|
||||
- `psgo.ProcessInfoByPids(pids []string, descriptors []string) ([][]string, error)`
|
||||
- ProcessInfoByPids is similar to `psgo.ProcessInfo`, but limits the return value to a list of specified pids. The pids input must be a slice of PIDs for which process information should be returned. If the input descriptor slice is empty, only the format descriptor headers are returned.
|
||||
|
||||
- `psgo.JoinNamespaceAndProcessInfo(pid string, descriptors []string) ([][]string, error)`
|
||||
- JoinNamespaceAndProcessInfo has the same semantics as ProcessInfo but joins the mount namespace of the specified pid before extracting data from /proc. This way, we can extract the `/proc` data from a container without executing any command inside the container.
|
||||
|
||||
- `psgo.JoinNamespaceAndProcessInfoByPids(pids []string, descriptors []string) ([][]string, error)`
|
||||
- JoinNamespaceAndProcessInfoByPids is similar to `psgo.JoinNamespaceAndProcessInfo` but takes a slice of pids as an argument. To avoid duplicate entries (e.g., when two or more containers share the same PID namespace), a given PID namespace will be joined only once.
|
||||
|
||||
- `psgo.ListDescriptors() []string`
|
||||
- ListDescriptors returns a sorted string slice of all supported AIX format descriptors in the normal form (e.g., "args,comm,user"). It can be useful in the context of bash-completion, help messages, etc.
|
||||
|
||||
@@ -28,6 +34,17 @@ root 4 2 0.000 6h3m27.678701852s ? 0s
|
||||
root 6 2 0.000 6h3m27.678999508s ? 0s [mm_percpu_wq]
|
||||
```
|
||||
|
||||
### Listing processes
|
||||
You can use the `--pids` flag to restrict `psgo` output to a subset of processes. This option accepts a list of comma separate process IDs and will return exactly the same kind of information per process as the default output.
|
||||
|
||||
```
|
||||
$ ./bin/psgo --pids 1,$(pgrep bash | tr "\n" ",")
|
||||
USER PID PPID %CPU ELAPSED TTY TIME COMMAND
|
||||
root 1 0 0.009 128h52m44.193475932s ? 40s systemd
|
||||
root 20830 20827 0.000 105h2m44.19579679s pts/5 0s bash
|
||||
root 25843 25840 0.000 102h56m4.196072027s pts/6 0s bash
|
||||
```
|
||||
|
||||
### Listing processes within a container
|
||||
Let's have a look at how we can use this library in the context of containers. As a simple show case, we'll start a Docker container, extract the process ID via `docker-inspect` and run the `psgo` binary to extract the data of running processes within that container.
|
||||
|
||||
@@ -38,7 +55,7 @@ $ docker run -d alpine sleep 100
|
||||
$ docker inspect --format '{{.State.Pid}}' 473c9
|
||||
5572
|
||||
|
||||
$ sudo ./bin/psgo -pid 5572
|
||||
$ sudo ./bin/psgo -pids 5572 -join
|
||||
USER PID PPID %CPU ELAPSED TTY TIME COMMAND
|
||||
root 1 0 0.000 17.249905587s ? 0s sleep
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user