git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: How to get bash to shut up about SIGPIPE?

From
PJPaul Jackson <pj@sgi.com>
Date
May 3, 2005, 01:44 UTC
Message-ID
<20050502184424.7cb7f2a4.pj@sgi.com>
In-Reply-To
<20050502231743.GL20818@pasky.ji.cz>
> Could you elaborate on how exactly is it supposed to help?
The key code is in bash/jobs.c.

If you have a bash while or for loop feeding a pipe that shuts down while the loop is still running commands that try to write the pipe (perhaps you were pipe'ing to "head -1", and it exit'd, having read its one line), then the next command to attempt to write that pipe will die, and the bash instance that is handling that loop (and forked that command that just died) will notice the command died with a SIGPIPE signal.

At this point, one of three possible things happens:
 1) If your bash is compiled with DONT_REPORT_SIGPIPE defined, then
    that bash instance quietly leaves.  The concensus around here
    is that is "good(tm)."
 2) If not so compiled, then:
	2a) If you set a trap on SIGPIPE in that shell, it prints:
		fprintf (stderr, "%s", j_strsignal (termsig));
	2b) Else if you did not trap SIGPIPE, it prints:
		fprintf (stderr, "%s: line %d: ", get_name_for_error (),
				(line_number == 0) ? 1 : line_number);
		pretty_print_job (job, JLIST_NONINTERACTIVE, stderr);
The pretty_print_job() in (2b) can be a multi-line confusion.
Sample output for (2a):
	Broken pipe
Sample output in simple one line case for (2b):
	foo: line 2: 11663 Broken pipe             cat /etc/termcap

A couple of others are reporting different behaviour than what I report above - including Linus.

So it is almost certain that I don't understand all I know about this.
What behaviour do you see?
-- 
                  I won't rest till it's the best ...
                  Programmer, Linux Scalability
                  Paul Jackson <pj@engr.sgi.com> 1.650.933.1373, 1.925.600.0401
Previous: Petr Baudis
Message 22 of 22 in “How to get bash to shut up about SIGPIPE?”
  1. Linus TorvaldsApr 28, 2005
  2. Rene ScharfeApr 28, 2005
  3. Linus TorvaldsApr 28, 2005
  4. Rene ScharfeApr 28, 2005
  5. Ryan AndersonApr 28, 2005
  6. Linus TorvaldsApr 28, 2005
  7. Herbert XuMay 1, 2005
  8. David A. WheelerMay 1, 2005
  9. Paul JacksonMay 2, 2005
  10. David A. WheelerMay 4, 2005
  11. Linus TorvaldsMay 4, 2005
  12. Herbert XuMay 4, 2005
  13. Edgar ToernigApr 28, 2005
  14. Linus TorvaldsApr 28, 2005
  15. Joshua T. CorbinApr 29, 2005
  16. Paul JacksonApr 30, 2005
  17. Linus TorvaldsApr 30, 2005
  18. Paul JacksonApr 30, 2005
  19. Rene ScharfeApr 30, 2005
  20. Paul JacksonMay 2, 2005
  21. Petr BaudisMay 2, 2005
  22. Paul JacksonMay 3, 2005

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.