On 07/07/15 12:46, alan buckley wrote:
The port I’m currently looking at uses pipe() and fork() to run a command
and communicates between the main program and an external program.
The main program itself fails with an invalid handle error from RISC OS, so
I thought I’d just check the pipe command and it doesn’t appear to be
working.
I’ve used the example from:
http://www.gnu.org/software/libc/manual/html_node/Creating-a-Pipe.html
and it gave no output instead of the text expected (and seen when I tried
the code on Ubuntu).
Should this be working on RISC OS?
If so is there something extra I should be doing?
If not, are there any suggestions on what to do instead?

Hi Alan, sorry it's taken me so long to get back to you on this.

I do believe that this is a problem in UnixLib.
The problem isn't with pipes, but with fork(). fork is somewhat
complicated because it is required to return twice, once for the
parent and once for the child. In your example, the order in
which the parent and child return is important; the parent should
return first so that the pipe is written to and then the child
returns and reads what the parent wrote.
In UnixLib, the child returns first and attempts to read from the
pipe before the parent has written anything, hence, the lack of
output.

I have yet to find any documentation on the web that defines the
order of return.

Looking at the cross compiler, I notice that it use vfork rather
than fork and it returns the child first, whereas your example
using fork (running in Linux) returns the parent first.

I naively attempted to fix it by swapping the return values in
(v)fork. This did in fact make your example work, but GCC was not
happy when I tested it, so I guess it's not as simple as that.

Maybe the process returned first is dependant on whether you're
using fork or vfork, but this is just guess work. I could do
with finding some documentation to verify my suspicions before
I make any changes.

Lee.


_______________________________________________
GCCSDK mailing list gcc@gccsdk.riscos.info
Bugzilla: http://www.riscos.info/bugzilla/index.cgi
List Info: http://www.riscos.info/mailman/listinfo/gcc
Main Page: http://www.riscos.info/index.php/GCCSDK

Reply via email to