Julian Gilbey wrote:
> I can't find much rhyme or reason to this one.  ls | head or ls -l |
> head sometimes dies with a broken pipe, but other times it doesn't.

Your report sounds like the classic problem of what happens when
people ignore SIGPIPE in the shell.  Some years back this was a
widespread problem.  Perhaps you have a SIGPIPE trap handler set in
your shell?

If this is the issue you see then the solution is to locate where
SIGPIPE is being ignored and remove it so that it can terminate the
writing process appropriately.  I can say more and explain the issue
in more detail if this is the problem.

What is the output of 'trap' at the command line?

  $ trap
  trap -- '' SIGTSTP
  trap -- '' SIGTTIN
  trap -- '' SIGTTOU

The easy way to recreate the case is with the following.  First the
normal case.

  $ trap
  trap -- '' SIGTSTP
  trap -- '' SIGTTIN
  trap -- '' SIGTTOU
  $ yes | head -n1
  y

Then set up the failure case by ignoring SIGPIPE.

  $ trap '' PIPE
  $ yes | head -n1
  y
  yes: standard output: Broken pipe
  yes: write error

Ignoring SIGPIPE creates the problem.

Bob

Attachment: signature.asc
Description: Digital signature

Reply via email to