Inter process communication

前端 未结 1 1560
再見小時候
再見小時候 2021-01-21 22:40

What are the pros and cons of using a file for interprocess communication? Let me give some background of the context I am asking this question in.

The problem is the c

相关标签:
1条回答
  • 2021-01-21 23:21

    I was faced with this choice recently and considered learning enough about Berkeley DB to use its queue mechanism. But ultimately I decided instead to use the Unix filesystem and write my own atomic queue primitives using Posix semaphores. If all processes are on one machine this is pretty easy. The atomic put function is about a dozen lines of code; the atomic get, because it has to wait if the queue is empty, is about three times the size.

    My advice is that you design an atomic-queue API that will hide these details. (Classic example of following Parnas's advice of using an interface to hide design details that are likely to change.) You can do the first version of the API using plain Unix file I/O. Then you can try variations like locking, Berkeley DB, or semaphores---all with the "minimum impact on the current process".

    You won't know performance impacts until you try something. File locking on real filesystems is pretty good; file locking on NFS is a bear.

    0 讨论(0)
提交回复
热议问题