in reply to Re: Processes clobbering each other
in thread Processes clobbering each other

So if one program says "aaa\nbbb\n" and the other says "ccc\nddd\n", in principle you may get "aaca\nbcbb\nc\nddd\n".

No, that is guaranteed not to happen. Unix pipes will not break up a single write(2) request to a pipe if it is smaller than the system buffer size for pipes (at least 512 bytes, perhaps more like 4kB). So unless you somehow manager to take more than one write(2) to output the "aaa\n", then it will not get any other data interleaved inside of it.

To get Perl to use more that one write(2) when outputting "aaa\n" you'd have to set $| to a true value and use more than one Perl statement to output those 4 characters.

                - tye
  • Comment on Re^2: Processes clobbering each other (atoms)

Replies are listed 'Best First'.
Re: Re^2: Processes clobbering each other (atoms)
by thospel (Hermit) on Nov 24, 2003 at 23:23 UTC
    Sure, that's why I later on say that linebuffered output of less than 512 bytes is safe. I was just explaining the concept and (over)simplifying things a bit.

    Notice by the way that when writing STDOUT to a tty perl is linebuffered and print "aaa\nbbb\n" will in fact become two writes, even without setting $|. But the real problem of course is the target program becoming blockbuffered (most likely with a blocksize fitting in a pipe which nowadays usually are 4K), but the block not ending on a lineboundary.

Re: Re^2: Processes clobbering each other (atoms)
by mcogan1966 (Monk) on Nov 25, 2003 at 13:54 UTC
    To get Perl to use more that one write(2) when outputting "aaa\n" you'd have to set $| to a true value and use more than one Perl statement to output those 4 characters.
    Though, there is a very distinct chance that this is exactly what is happening. Hard to say for sure. So, I tried commenting out the
    $| = 1;
    line. Didn't work though.