buffering question: interleaved output from child processes

J

Joel VanderWerf

The following code, when connected to the terminal's stdio, interleaves
the outputs in time-order.

When I pipe the stdout or redirect to a file, all the "B" outputs are
grouped at the top (in time order), followed by the "A" outputs.

I assume this is due to buffering in the child processes. What can I do
to make the piped/redirected output behave like terminal output?

$ ruby -v
ruby 1.9.0 (2004-01-08) [i686-linux]

----

$stdout.sync

START_TIME = Time.now.to_f

fork do
srand 1
10.times do
sleep rand
puts "A: #{Time.now.to_f - START_TIME}"
end
end

fork do
srand 2
10.times do
sleep rand
puts "B: #{Time.now.to_f - START_TIME}"
end
end

Process.wait
Process.wait
 
N

nobu.nokada

Hi,

At Sat, 14 Feb 2004 17:18:07 +0900,
Joel VanderWerf wrote in [ruby-talk:92863]:
I assume this is due to buffering in the child processes. What can I do
to make the piped/redirected output behave like terminal output?

$stdout.sync = true
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top