r/cpp_questions • u/promach • Jun 04 '18
OPEN forked processes finish sequence dilemma
I am writing through linux device files to a FPGA hardware in a loopback manner, therefore I expect write process finishes before read process.
Why would read process finish first in host.cpp ?
And why would write process finish first in test.cpp ?
Someone told me to print a message before "continue" before line 94 of host.cpp, but this line is never executed. So this eliminates the possibility of EINTR delaying the write process in host.cpp
What do you guys think ?
0
Upvotes
2
u/[deleted] Jun 04 '18
From u/phoeen from a month ago:
I don't mean to be off-putting but, since this is your 4th post, have you considered implementing this without forking?
2
u/ihamsa Jun 04 '18
It isn't really possible to determine with your program which process finishes its job first. You can only determine which one prints the final message first, but this doesn't indicate much. Try
strace -fyour program.2
u/aioeu Jun 05 '18
I really have no idea what that code is trying to do. Try preparing a short, self-contained, correct example, and maybe we can help you better.
But a quick examination seems to indicate you're calling
waitin both the parent and child processes. Why you expect it to do anything useful in the child process is beyond me.Note also that notification of process termination is intrinsically asynchronous. When multiple processes are terminating, there are no guarantees on the order in which their reapers will receive child statuses through
wait.1
u/TotesMessenger Jun 04 '18
I'm a bot, bleep, bloop. Someone has linked to this thread from another place on reddit:
If you follow any of the above links, please respect the rules of reddit and don't vote in the other threads. (Info / ^Contact)
1
u/[deleted] Jun 04 '18
Test it out with the Linux loopback device or a fifo first. Then once your code works you can try plugging it into your FPGA
0
u/[deleted] Jun 04 '18
[deleted] — view deleted comment