Tubes vs tmfiles. Which is better and why?

I want to write a program that creates a child process and redirects the stdout and stderr threads to the parent. So what is the good choice to make tmpfile () or pipe () for good performance and why?

+4
source share
3 answers

Use pipe if possible, unless you expect large volumes of input to be created in the stream without reading. The pipe stores data in RAM, where a temporary file requires file system operations. fdsync in a file will be much more expensive than on a pipe. The pipe is also less vulnerable to safety problems caused by race conditions.

If your application cannot use channel semantics (requires a path to the file system to output it or a similar problem), try using a "named pipe" (also called FIFO).

+6
source

Pipes would be ideal if they did not have one serious flaw: a fixed buffer size. When using pipes, a slow consumer throttles the manufacturer, which in turn causes too many context switches ...

0
source

The main disadvantage of the pipe is that it is not searchable, that is, the consumer cannot skip forward or backward. If data exchange does not require this property, then the pipe is the best choice.

0
source

Source: https://habr.com/ru/post/1341639/


All Articles