Home » Questions » Computers [ Ask a new question ]

Does pipe have to write temporary file?

Does pipe have to write temporary file?

I found that if I transfer a great amount of data between two processes via pipe, some temporary file will be created by linux in /tmp directory. If the pipe operation succeeds, the corresponding temporary file will be removed by OS automatically. But if the operation failed, the tmp file remains there.

Asked by: Guest | Views: 156
Total answers/comments: 2
Guest [Entry]

"pipes don't store data on disk. /bin/echo foo | grep bar doesn't create any files. try strace -f sh -c '/bin/echo foo | grep bar' to see all the system calls made by a shell when running a pipeline. echo is a shell builtin, so I suggested /bin/echo to make the shell run an executable.
/tmp doesn't have to be on disk. It can be mounted on tmpfs (i.e. backed by virtual memory). Note that a reboot will empty /tmp in that case, so use /var/tmp for anything you want to leave around.

If what you're doing is putting data into a file, then it's not using a pipe. If the file is a fifo, not a regular file, then it's just a named rendezvous, and doesn't contain data. Use ls -l to find out.

And note that if you're hoping to stop users from seeing what's going through pipes in processes they own, you are pretty much SOL, because strace can inspect everything a process does that interacts with anything outside the process, except for reading/writing mmapped shared memory. ltrace is even more invasive. If your program will run on systems where the local user has root, you can't stop them at all. On Unix, root can do anything, and has powerful tools for the purpose."
Guest [Entry]

"Dirty hack:
Encrypt the data before sending
and decrypt it on receiving if you can change both of the processes ..."