Bash, tar, and broken pipe

Chet Ramey chet at odin.INS.CWRU.Edu
Thu May 23 05:29:14 AEST 1991


In article <heinz.674916703 at cc.univie.ac.at> heinz at cc.univie.ac.at () writes:

>This does not explain the broken pipe, though. I tried the following:
>
>	cat <some_long_file> | more
>
>and killed 'more' by pressing 'q' at the first prompt (so more terminates
>first). No 'Broken Pipe'.

I guess I'll take a shot at this one.  First of all, other shells (csh and
ksh for sure) special-case the message printed when a child process dies due
to an interrupt (SIGINT) or a broken pipe (SIGPIPE).  Bash does not skip
over SIGPIPE, hence the unexpected `Broken Pipe' message.

>Then I tried:
>
>	echo Hallo | (sleep 10; more) # first process terminates first, since
>		'Hallo' should fit into the pipe's buffer
>
>No 'Broken Pipe' either.

Try

slc2$ cat /etc/termcap | sleep 1
Broken pipe

(I also get the `Broken Pipe' message when I do `cat /etc/termcap | more' and
immediately hit `q'.)

The broken pipe/SIGPIPE/EPIPE happens to the *first* process in a pipeline;
the error occurs when an attempt is made to write on a pipe when no process
has it open for reading.

The process must exit due to the SIGPIPE, by the way -- no message will be
printed if it catches the SIGPIPE and calls exit(), unless the fatal signal
handler is coded like this:

fatal(sig)
int	sig;
{
	cleanup();
	_exit(128+sig);
}

>Maybe I should take the time and hack up the source code of bash,
>but I'm not sure if it's worth the effort.

It's a several-minute job, to be sure ;-)

Chet
-- 
Chet Ramey			  Internet: chet at po.CWRU.Edu
Case Western Reserve University	  NeXT Mail: chet at macbeth.INS.CWRU.Edu

``Now,  somehow we've brought our sins back physically -- and they're pissed.''



More information about the Comp.unix.shell mailing list