Answer the question
In order to leave comments, you need to log in
One-way transfer of information between processes?
Hello, I
describe the situation:
there is a parent process ( WindowProc is present), which spawns a new, child process. The child process needs to somehow notify the parent process about the progress of some task - that is, in fact, pass numbers from 0 to 100 (or from 0 to 1, not so important). But you need to do this without any delay in the child process (i.e. write to the memory map , send an event and wait for another event about the read success; for the same reason, you won’t be able to use pipe , since you will need to wait for a “connection” ( ConnectNamedPipe )).
Is there any solution?
Answer the question
In order to leave comments, you need to log in
You can use WM_USER window messages via PostMessage. You are passing integers that fit into lParam, wParam, so you don't even have to transfer data through shared memory, pipes and sockets.
It is not even necessary to create a window for this, you can use PostThreadMessage.
In the parent process, read the notification in the message loop. If there is none, then create in a new thread.
My options:
1. The simplest is stdout, which is also standard output. If you redirect it to an anonymous pipe, then the parent process will be able to read what the child writes there. If the parent process terminates, the child will receive an error when writing to the pipe. A child process may hang in only one case - if it writes more than 4KB of text to the pipe, and the parent does not read it.
2. Similar to the first - create a pair of TCP sockets connected to each other. Advantage - the child process can now use non-blocking mode, which will prevent it from blocking (at the cost of losing some of the data if the parent does not read them).
3. Just use a circular buffer in shared memory, with a one-way setting of some event. You can even use a buffer of size 1 - that is, always write to the same place. Data may be lost, but this is not essential for progress notification.
4. Use a shared semaphore - the child process does Release, the parent - Wait. The disadvantage is that asynchronous waiting is impossible, there is no transmission, in fact, of messages - only counting.
If for some reason you can not redirect the output, then I would choose UDP.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question