off topic: combined output of concurrent processes

Amadeus W.M. amadeus84 at verizon.net
Sun Apr 15 02:32:50 UTC 2012


> 
> | Multiple processes that open the same file for writing each maintain |
> their own file positions, so they may overwrite the output of another |
> process, unless the processes all open the file with the "O_APPEND" |
> option.
> 
> This only matters if the processes _independently_ opened the file. So
> this:
> 
>   echo AAA >foo &
>   echo BBB >foo &
> 
> pretty much _will_ overwrite each other. But the OP effectively has
> this:
> 
>   ( echo AAA &
>     echo BBB &
>   ) >foo
> 
> Only _one_ open file handle in play. The writes may happen in either
> order but they will _not_ overwrite each other because there is only one
> file handle, and thus only one file position pointer.
> 

This is a fine point and it does make sense. However, why do I not get 
all 100 blocks of As, 100 blocks of Bs, etc. The for loop has 100 
iterations, so there should be 100 lines each. 

Also, how would I know I'm overwriting the buffer. The output of each 
process (the echo in the example) is not 500 bytes but more like 30-40 
Kb, possibly more, but not Mb.




More information about the users mailing list