开发者

Difference between shared memory and pipe in unix?

what is main difference between shared memory and 开发者_运维知识库pipe in unix programming?


Taken from this article

(unnamed) Pipes

  • Can switch between blocking and non-blocking mode
  • Don't have to free them when done
  • Are automatically inherited by children
  • Must read and write in a linear fashion

Shared Memory

  • Can store structures
  • Won't ever block - positive
  • Can have as many programs read or write to it as you need
  • Won't ever block - negative: must use semaphores or your own spin-locks
  • It's possible for it to not be freed even when all programs exit


Shared Memory Vs Pipe-

Kernel-

Once Shared Memory is setup by the kernel there is no further need of kernel for the communication b/w process whereas in Pipe, data is buffered in the kernel space and requires system call for each access. Here, Shared Memory is faster than Pipe. It is a major drawback of the pipe becuase IPC is important for the computational speed up.

Communication

Shared Memory- Bidirectional whereas Pipe(unnamed Pipe)- Unidirectional.

Reliable

Shared Memory- Less Reliable(data mix up) whereas Pipe is more Reliable as data is buffered and is under control of the kernel.

Hope you like it.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜