是否建议在bash脚本中捕获SIGPIPE? [英] Is it recommended to trap SIGPIPE in bash script?
问题描述
使用系统调用命令从C ++执行bash脚本时遇到问题.该脚本捕获 SIGPIPE
信号,并返回返回代码 141
.
I have a problem while executing a bash script from C++ using the system call command.
The script catches a SIGPIPE
signal and exit with return code 141
.
此问题仅在我的代码的最新版本中开始出现.
This problem has started to appear only in the last release of my code.
我的问题如下:
- 为什么此SIGPIPE现在发生而以前没有发生?
- 忽略SIGPIPE是否安全,后果如何?
推荐答案
1)如果不确切知道所做的更改,很难回答.
2)如果一系列命令出现在管道中,并且其中一个读取命令在写入器完成之前完成,则写入器会收到SIGPIPE信号.因此,是否可以忽略它取决于脚本的可接受行为.更多信息此处
1) That's very hard to answer without knowing exactly what you changed.
2) If a sequence of commands appears in a pipeline, and one of the reading commands finishes before the writer has finished, the writer receives a SIGPIPE signal. So whether you can ignore it depends on whether that is acceptable behavior for your script. More info here
这篇关于是否建议在bash脚本中捕获SIGPIPE?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!