tneff@bfmny0.UUCP (Tom Neff) (08/04/89)
I don't know if the following is a bug or a feature, but it exists. I had a complex backup script which I was running under the Bourne shell. The business end of it ended up evaluating to something like find / -print | fgrep -v /tmp/ | fgrep -v /spool/ | \ pax -wv | compress | team 32k 4 > /dev/rmt/c0s0 so there were about 6 processes in a pipeline. That 'team' (it's a buffering copy for tape streaming which has been posted in comp.sources.misc, and I recommend it highly) itself creates 3 more processes, so you might say there were 9, but only 6 created by the shell itself. Anyway the problem is that control returns to the shell when 'find' is done but BEFORE the later stages of the pipeline are done! In particular the 'pax' and 'compress' and 'team' guys keep going. I could not find an effective way to synchronize the shell with the pipeline. However when I switched to Korn shell, which we also own (I just don't normally use it for system scripts), lo and behold the shell waits for ALL the pipeline processes to complete before continuing the script. So, I am happy for now, but I don't understand what was happening with /bin/sh. Can anyone shed some light? -- "We walked on the moon -- (( Tom Neff you be polite" )) tneff@bfmny0.UU.NET
gors@well.UUCP (Gordon Stewart) (08/05/89)
Typically, there is one FIFO (a special kind of file that implements pipes) open for each symbol "|" in a line of shell script. The flow is designed in such a way that reading processes have input and writing processes can write, and nobody will read on an empty pipe. This means that there will typically be stuff in all the pipes in a 'sh' command, with the processes runnning concurrently. -- {apple, pacbell, hplabs, ucbvax}!well!gors gors@well.sf.ca.us (Doolan) | (Meyer) | (Sierchio) | (Stewart)
henry@utzoo.uucp (Henry Spencer) (08/06/89)
In article <14511@bfmny0.UUCP> tneff@bfmny0.UUCP (Tom Neff) writes: >However when I switched to Korn shell, which we also own (I just don't >normally use it for system scripts), lo and behold the shell waits for >ALL the pipeline processes to complete before continuing the script. >So, I am happy for now, but I don't understand what was happening with >/bin/sh. Can anyone shed some light? Historically, getting the parent/child relationships right in long pipelines has been difficult, and many older Bourne shells don't do it quite right. The most modern ones do, I think. -- 1961-1969: 8 years of Apollo. | Henry Spencer at U of Toronto Zoology 1969-1989: 20 years of nothing.| uunet!attcan!utzoo!henry henry@zoo.toronto.edu