开发者

pipes vs tmfiles. What is better and why?

I want write program which creates child proces开发者_运维百科s and redirecting its stdout and stderr streams to parent. So what is good choice to do this for good performance tmpfile() or pipe(), and why?


Use pipe where possible, unless you expect large amounts of input to build up in the stream without being read. A pipe keeps data in RAM where a temporary file requires filesystem operations. An fdsync on a file will be much more expensive than on a pipe. A pipe is also less vulnerable to security issues caused by race conditions.

If your application cannot use pipe semantics (requires a filesystem path for its output or a similar problem), try using a "named pipe" (also called a FIFO).


Pipes would be perfect if they did not have one major drawback: fixed buffer size. When using pipes a slow consumer throttles the producer, which in turn, causes too much context switching...


The major drawback for a pipe is that it is not seekable, that is, the consumer cannot skip ahead or rewind. If the data exchange does not require this property, then a pipe is the better choice.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜