Reputation: 369
I am working on a project where i need to set up a communication between parent process and child processes, i was using named pipes for IPC but i have heard that named pipes won't guarantee mutual exclusion. What would be the best IPC technique which can guarantee mutual exclusion?
Upvotes: 0
Views: 219
Reputation: 30235
What you want is a Unix domain socket (AF_UNIX
) with datagrams (SOCK_DGRAM
) instead of a stream (this is kind of like a reliable, local UDP). That way you can multiplex sending and receiving without having to resort to locking.
An other alternative would be using message queues, but that's considered a bit obscure nowadays.
Upvotes: 1
Reputation: 30235
You can use named pipes in combination with flock/fcntl if you want mutual exclusion, but that's only workable when either the reader (preferably) or the writer end is singular (the end with multiple clients would use the locks).
Upvotes: 0