Reputation: 261
I think maybe this is an obvious question, but I just want to be sure by asking you guys.
I'm working with parent-child process communication using the pipe system call to create a unnamed pipe.
My child process needs to gather some information and send it to its parent. My questions are:
Thank you very much!
Upvotes: 0
Views: 1487
Reputation: 61369
You can write()
and read()
struct
s just fine; use a pointer to the struct
as the buf
parameter. It's when you want to do this between processes not running on the same machine that you run into problems and need to do marshaling/unmarshaling to portable representations to insure the values are understood the same way everywhere. This includes recognizing the start and end of data "packets", since a pipe doesn't really have the concept of packets: if all you're doing is writing a series of identical struct
s, then you can just write()
them and the reader can rely on read()
returning 0 to indicate the end of the series; but if you need to send other information as well then you'll need a framing protocol to say "what follows is such-and-such struct
", "what follows is a string", etc.
Upvotes: 2