Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it recommended to trap SIGPIPE in bash script?

Tags:

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.

My Questions are as follows:

  1. Why does this SIGPIPE occur now and didn't occur before?
  2. Is it safe to ignore the SIGPIPE and what are the consequences?
like image 595
Eyalk Avatar asked Jan 25 '10 09:01

Eyalk


1 Answers

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

like image 173
PiedPiper Avatar answered Oct 25 '22 05:10

PiedPiper