off topic: combined output of concurrent processes

Ed Greshko Ed.Greshko at greshko.com
Sat Apr 14 13:49:00 UTC 2012


On 04/14/2012 09:33 PM, Dave Ihnat wrote:
> On Sat, Apr 14, 2012 at 01:35:38AM +0000, Amadeus W.M. wrote:
>> So here is the question. Suppose I have several processes that run 
>> concurrently and each outputs stuff to stdout. Can the combined output be 
>> intermingled? 
> If you just send the output to a file, you've no way of knowing exactly
> when it will be output, or whether it will be buffered before writing.
> You can mitigate this a bit by making every output line have a sequence and
> process identifier--the PID and date in seconds would work--so you could
> separate the streams later.
>
> If you really would like to get output in sequence, write to a pipe, and
> have a reader process drain the pipe to a logfile.  It's pretty easy; look
> at "mknod" with the 'p' option, or "mkfifo".  I'd still suggest tagging
> each output line with an identifier and sequence number.
>

Yes, the pipe idea would work well and ensure you get all the output.

The one problem would be if, as the OP's script is written, backgrounding of
processes is done there is no way to control the order of data being written to the
pipe.  And, as you pointed out, you may want to write out sequence numbers if that is
important.

-- 
Never be afraid to laugh at yourself, after all, you could be missing out on the joke
of the century. -- Dame Edna Everage


More information about the users mailing list