Skip to content
Advertisement

linux C sending data from child to parent is fine, but fail to send data from child to parent

I would like to fork a child and connect pipes to the stdin and stdout of child. And then run the exec ./xx. After that I send 17 from parent to child and child print it. all good so far. but when I send a 17 return to parent it doesnt work. The result is : output nothing and look like wait for some input. if I remove the code “fscanf(b, “%d”, &x); ” in parent, the output is: from C 0 from p 17 I pretty confuse why I get the odd result?? Thank you

JavaScript

XX

JavaScript

Advertisement

Answer

Use this code:

JavaScript

And xx:

JavaScript

It’s working for me 🙂

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement