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

179 天前
 laminux29
mkfifo test-fifo

bash < test-fifo

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

请问这是 bug 吗?还是我的姿势不对?
378 次点击
所在节点    PowerShell
4 条回复
jifengg
178 天前
linux 命令里, < 和 > 表示输入输出的重定向,| 表示管道符,他们后面的语句已经不是前面语句的命令行参数了,就比如你的“ps -ef | grep bash”,本身也是创建了两个进程“ps”和“grep”,你同样无法用 ps 看到你这行“ps -ef | grep bash”
laminux29
178 天前
@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
178 天前
Debian 12-2-0

CentOS 7.9

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

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

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/991168

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX