如何在Alpine中使用ps命令获取特定PID的进程名称 [英] How can I get process name of specific PID with ps command in alpine
问题描述
在基于ubuntu的docker/os中
In ubuntu based docker/os
$ ps
PID USER TIME COMMAND
1 postgres 0:00 postgres
47 postgres 0:00 postgres: checkpointer process
48 postgres 0:00 postgres: writer process
49 postgres 0:00 postgres: wal writer process
50 postgres 0:00 postgres: autovacuum launcher process
51 postgres 0:00 postgres: stats collector process
52 postgres 0:00 postgres: bgworker: logical replication launcher
现在,如果运行ps -p 1 -o user=
,它将为我 PID 1 处理USER postgres
Now If run ps -p 1 -o user=
, it will get me PID 1 process USER postgres
$ ps -p 1 -o user=
postgres
这是我在基于ubuntu
的图像/操作系统中可以做的
This is what I can do in ubuntu
based image/os
现在
我真的在寻找一种方法来对基于alpine
的图像执行相同的操作.在哪里可以运行ps
命令来获取 PID 1 进程USER.
I am really seeking for a way to do the same for alpine
based image. Where I can run ps
command to get PID 1 process USER.
我没有找到任何文档/提示.
I didn't find any docs/hints around.
推荐答案
默认情况下,高山图像中的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
这篇关于如何在Alpine中使用ps命令获取特定PID的进程名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!