If you don't want to sleep, you could also just collect the output together, rather than printing it in different stages. When you print to a file (and STDOUT is still a file) you are asking perl and the OS to handle the output for you which may not always work in the way you expect. Normally that's not a problem, but if you have different processes all trying to access the same resource (STDOUT for each process is competing for the same terminal session) it probably won't happen quite as you expect.
So ... you could use something like:
for (1..3) { my $fork_pid = fork(); if (! $fork_pid) { my ($Output); $Output="hello\t"; $Output.=`ps au`; $Output.="world\n"; print $Output; exit 0; } }
This keeps the print a single item which is probably going to be written in one go (and hence stay together) as you want. Of course I am sure that your real code is doing something much more interesting than just printing output :o)
In reply to Re: Backticks within child process
by The Code Captain
in thread Backticks within child process
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |