开发者

Inter process communication on the same machine,signal or socket,how to decide?

It 开发者_开发技巧seems to me that both signal and socket can be used for this job,

how do you decide which one to use actually?


Using signals for IPC is sort of inconvenient and primitive. You should really be choosing between Unix sockets (not TCP ones!) and pipes.

Pipes are generally easier to program with, since they guarantee that a single write under the size of PIPE_BUF is atomic. They do have their limitations however. For example, when the writer is faster than the reader, the writer starts to block when the pipe buffer gets full. The size of this buffer by default is around 64k, and it cannot be changed without recompiling the kernel, at least in Linux. Pipes are also unidirectional, which means that you'll have to keep a pair of pipes in each process, one for reading and one for writing.

Unix sockets have a configurable send buffer size and a more advanced programming interface.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜