in reply to forking messages

So you fork 10 times and then all of the processes try to send output to a single source? I don't think you understand the concept of fork very well.

When you fork, you create another process in memory that has an independent set of memory and execution paths. Thus, you really have two programs that can do separate things without marching on top of each other. In your case, you have 10. Since a computer can only run one instruction at a time, the operating system simulates this by switching between the processes for you.

But on most PCs, there is only one STDOUT. So each process is now writing to a single device. The reason your output becomes garbled is because the OS is scheduling the threads in an otder it feels is best, and this isn't what you would expect.

If you need a particular order, don't fork.