ps 无法显示 bash 命令的完整参数,是 bug 吗? - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
laminux29
V2EX    PowerShell

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

  •  1
     
  •   laminux29 2023-11-12 15:08:45 +08:00 1211 次点击
    这是一个创建于 765 天前的主题,其中的信息可能已经有所发展或是发生改变。
    mkfifo test-fifo

    bash < test-fifo

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

    请问这是 bug 吗?还是我的姿势不对?
    jifengg
        1
    jifengg  
       2023-11-13 16:13:47 +08:00
    linux 命令里, < 和 > 表示输入输出的重定向,| 表示管道符,他们后面的语句已经不是前面语句的命令行参数了,就比如你的“ps -ef | grep bash”,本身也是创建了两个进程“ps”和“grep”,你同样无法用 ps 看到你这行“ps -ef | grep bash”
    laminux29
        2
    laminux29  
    OP
       2023-11-13 18:52:14 +08:00
    @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
       2023-11-13 18:53:15 +08:00
    Debian 12-2-0

    CentOS 7.9

    bash 都有这个问题,tail 都没这个问题。
    laminux29
        4
    laminux29  
    OP
       2023-11-15 00:08:31 +08:00
    破案了:

    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     Solana     1360 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 23ms UTC 6:56 PVG 00:56 LAX 08:56 JFK 11:56
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86