【问题标题】:How can I get process name of specific PID with ps command in alpine如何在 alpine 中使用 ps 命令获取特定 PID 的进程名称
【发布时间】:2018-07-17 06:22:04
【问题描述】:

在基于 ubuntu 的 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 进程用户postgres

$ ps -p 1 -o user=
postgres

这就是我可以在基于ubuntu 的图像/操作系统中做的事情

现在

我真的在寻找一种方法来为基于alpine 的图像做同样的事情。我可以在哪里运行 ps 命令来获取 PID 1 进程 USER。

我没有找到任何文档/提示。

【问题讨论】:

    标签: process pid ps alpine


    【解决方案1】:

    默认情况下,alpine 图像中的ps 有非常剪裁的版本。是busybox一:

    / # 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
    

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

    如果要使用uncut ps,需要先安装到alpine镜像:

    / # 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
    

    现在,你可以随心所欲地使用它了:

    / # ps -p 1 -o user=
    root
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-04-16
      • 2020-09-29
      • 2012-12-20
      • 2012-01-22
      • 2015-06-09
      • 1970-01-01
      • 1970-01-01
      • 2015-02-16
      相关资源
      最近更新 更多