0

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?

napster
  • 349
  • 1
  • 4
  • 16
  • 1
    Can you describe issue in more details? – mpapec May 09 '14 at 10:55
  • Actually parent process is assigning work between child processes and each child is picking a row from database table and performing some operation with it. Unfortunately it is hard for a child to know which row was already taken by other child. What technique should i use so that each child will pick a different row?? – napster May 09 '14 at 17:07
  • hi @mpapec, you got my question?? – napster May 11 '14 at 11:28
  • I would change approach and tell every child which row to pick. – mpapec May 11 '14 at 11:57

2 Answers2

1

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.

Leon Timmermans
  • 30,029
  • 2
  • 61
  • 110
0

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).

Leon Timmermans
  • 30,029
  • 2
  • 61
  • 110
  • both reader and writer end is non-singular. Is there any other IPC technique can be used here?? – napster May 09 '14 at 10:19