tar fs copy

Alan Fargusson alan at drivax.UUCP
Mon Sep 16 15:45:04 AEST 1985


> 
> Wait a minute!  I have a Bourne shell script called cphier which contains the
> following and runs fine.
> 
> if [ $# -ne 2 ]
> then
> 	echo usage: cphier frompath topath
> fi
> exec tar cf - $1 | (cd $2; tar xf - )
> 
> What am I doing wrong?

It doesn't always fail. The problem is that sh(1) makes the first
tar a child of the second tar. If the second tar has to create a
directory it does a fork/exec of mkdir, then waits for all of its
children to die, including the first tar. Now if the first tar is
nearly finished then it will write its output to the pipe and exit,
which allows the second tar to continue. However, if the first tar
has to write more than what will fit in the pipe then the whole mess
hangs up, because the first tar is waiting for the second tar to
read from the pipe, and the second tar is waiting for the first tar
to exit.
-- 

Alan Fargusson.

{ ihnp4, amdahl, mot }!drivax!alan



More information about the Comp.unix.wizards mailing list