gpt4 book ai didi

perl - perlipc 文档中的错误?

转载 作者:行者123 更新时间:2023-12-04 15:35:50 24 4
gpt4 key购买 nike

我试图解开我在 perlipc 中看到的东西文档。

If you're writing to a pipe, you should also trap SIGPIPE. Otherwise, think of what happens when you start up a pipe to a command that doesn't exist: the open() will in all likelihood succeed (it only reflects the fork()'s success), but then your output will fail--spectacularly. Perl can't know whether the command worked because your command is actually running in a separate process whose exec() might have failed. Therefore, while readers of bogus commands return just a quick end of file, writers to bogus command will trigger a signal they'd better be prepared to handle. Consider:


   open(FH, "|bogus")  or die "can't fork: $!";
print FH "bang\n" or die "can't write: $!";
close FH or die "can't close: $!";

That won't blow up until the close, and it will blow up with a SIGPIPE. To catch it, you could use this:


   $SIG{PIPE} = 'IGNORE';
open(FH, "|bogus") or die "can't fork: $!";
print FH "bang\n" or die "can't write: $!";
close FH or die "can't close: status=$?";

如果我没看错,它说第一个版本可能会在最后关闭之前消失。

但是,这不会发生在我的 OS X 机器上(Perl 版本 5.8.9 到 5.15.9)。它在 open 上爆炸不管我是否有 $SIG{PIPE} 行,都带有“无法 fork :没有这样的文件或目录”。

我有什么误解?

最佳答案

这是在 5.6 的开发过程中实现的更改,以便 system() 可以检测何时无法 fork/exec 子项

https://github.com/mirrors/perl/commit/d5a9bfb0fc8643b1208bad4f15e3c88ef46b4160

它也记录在 http://search.cpan.org/dist/perl/pod/perlopentut.pod#Pipe_Opens

它本身指向 perlipc,但 perlipc 似乎确实缺少这个

关于perl - perlipc 文档中的错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10456916/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com