且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Alpine中使用ps命令获取特定PID的进程名称

更新时间:2021-10-19 01:20:01

默认情况下,高山图像中的ps版本非常删减.这是一个繁忙的信箱:

There is very cut version of ps in alpine image by default. It is busybox one:

/ # ps --help
BusyBox v1.27.2 (2017-12-12 10:41:50 GMT) multi-call binary.

Usage: ps [-o COL1,COL2=HEADER]

Show list of processes

    -o COL1,COL2=HEADER Select columns for display

它只能显示带有已定义列的输出.

It can only show output with defined columns.

如果要使用未剪切的ps,则需要先将其安装到高山图像上:

If you want use uncut ps, you need to install it first to alpine image:

/ # apk add --no-cache procps
fetch http://dl-cdn.alpinelinux.org/alpine/v3.7/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.7/community/x86_64/APKINDEX.tar.gz
(1/6) Installing libintl (0.19.8.1-r1)
(2/6) Installing ncurses-terminfo-base (6.0_p20171125-r0)
(3/6) Installing ncurses-terminfo (6.0_p20171125-r0)
(4/6) Installing ncurses-libs (6.0_p20171125-r0)
(5/6) Installing libproc (3.3.12-r3)
(6/6) Installing procps (3.3.12-r3)
Executing busybox-1.27.2-r7.trigger
OK: 13 MiB in 17 packages

现在,您可以使用它了:

Now, you can use it you want:

/ # ps -p 1 -o user=
root