V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
laminux29
V2EX  ›  PowerShell

ps 无法显示 bash 命令的完整参数,是 bug 吗?

  •  1
     
  •   laminux29 · 167 天前 · 349 次点击
    这是一个创建于 167 天前的主题,其中的信息可能已经有所发展或是发生改变。
    mkfifo test-fifo

    bash < test-fifo

    用 ps -ef | grep bash 就无法找到 bash < test-fifo 这条完整命令。

    请问这是 bug 吗?还是我的姿势不对?
    jifengg
        1
    jifengg  
       166 天前
    linux 命令里, < 和 > 表示输入输出的重定向,| 表示管道符,他们后面的语句已经不是前面语句的命令行参数了,就比如你的“ps -ef | grep bash”,本身也是创建了两个进程“ps”和“grep”,你同样无法用 ps 看到你这行“ps -ef | grep bash”
    laminux29
        2
    laminux29  
    OP
       166 天前
    @jifengg

    但问题是:

    cp /usr/bin/bash /usr/bin/xxxxbash

    mkfifo /tmp/test-fifo

    xxxxbash < /tmp/test-fifo

    另开一个窗口:

    ps -ef | grep bash

    仍然看不到 xxxxbash

    cat /proc/bash-id/status 里面的信息,发现第一行:

    Name: bash

    我猜测这是被硬编码了。

    对比一下:

    cp /usr/bin/tail /usr/bin/xxxxtail

    xxxxtail -f /tmp/test-fifo

    另开一个窗口:

    watch -n 1 "ps -ef | grep tail"

    这下子能看到 xxxxtail 了,并且:

    cat /proc/xxxxtail-id/status

    第一行 Name 被正确改为 xxxxtail


    所以,这 bash 在 proc 的 status 的 name ,是个硬编码的 bug 吧?
    laminux29
        3
    laminux29  
    OP
       166 天前
    Debian 12-2-0

    CentOS 7.9

    bash 都有这个问题,tail 都没这个问题。
    laminux29
        4
    laminux29  
    OP
       164 天前
    破案了:

    cp /usr/bin/bash /usr/bin/bashV1
    cp /usr/bin/bash /usr/bin/bashV2

    /usr/bin/bashV1
    # 当前 bash 环境切换到了 bashV1

    mkfifo /tmp/test-fifo
    /usr/bin/bashV2 < /tmp/test-fifo

    # 如果管道没有输入,则一直卡在 bashV1 里,现在 ps 也只能看到 bashV1
    # 当管道有输入,则 bashV2 会在一瞬间就完成了,ps 来不及跟踪,当然显示不了 bashV2
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2966 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 40ms · UTC 13:11 · PVG 21:11 · LAX 06:11 · JFK 09:11
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.