Reputation: 18228
Is there a way to synchronize output to standard output streams (be it C's stdout
or C++'s std::cout
) between unrelated processes so that the output of unrelated processes does not get interspersed?
Upvotes: 0
Views: 557
Reputation: 27542
Depends on what you mean by unrelated. The processes can be unrelated in the sense that there is no parent/child relationship but they still have to be programmed to cooperate in some way, be that a semaphore, mutex, file lock, or whatever. There is no secret system call (that I am aware of) that will automatically synchronise two separate streams from two separate processes.
Upvotes: 1
Reputation: 561
Although there is a function named sync_with_stdio
, this does not do what you're thinking.
You will need to use some OS-provided synchronization primitives like boost::scoped_lock
with boost::mutex
(within one process) or the Boost.MPI primitives for inter-process synchronization.
Upvotes: 2