小编mac*_*ium的帖子

当通过其他命令进行管道传输时,pgrep 返回额外的进程

这是一个非常奇怪的问题,关于使用 pgrep 搜索哪些 shell 进程正在运行与当前进程相同的脚本。

\n

这是名为test.sh的测试脚本

\n
#!/bin/bash\n\nfull_res=`pgrep -a -l -f \'test\\.sh\'`\n\nres=$(pgrep -a -l -f \'test\\.sh\' | cat)\n\necho "short result is $full_res"\n\necho "weird result is $res"\n
Run Code Online (Sandbox Code Playgroud)\n

输出为

\n
sh test.sh &\n[1] 19992\n\xe2\x9e\x9c  logs short result is 19992 sh test.sh\nweird result is 19992 sh test.sh\n19996 sh test.sh\n\n[1]  + 19992 done       sh test.sh\n
Run Code Online (Sandbox Code Playgroud)\n

我不知道这些声音从何19996 sh test.sh而来,尤其是在使用管道猫时。我相信这可能是 pgrep 实现的一个错误。

\n

期待合理的解释

\n

谢谢,

\n

巴林

\n

linux shell pgrep

5
推荐指数
2
解决办法
866
查看次数

标签 统计

linux ×1

pgrep ×1

shell ×1