Search code examples
pythonlinuxproctmpfs

How to write file to RAM on Linux


A program that I can not modify writes it's output to a file provided as an argument. I want to have the output to go to RAM so I don't have to do unnecessary disk IO. I thought I can use tmpfs and "trick" the program to write to that, however not all Linux distros use tmpfs for /tmp, some mount tmpfs under /run (Ubuntu) others under /dev/shm (RedHat). I want my program to be as portable as possible and I don't want to create tmpfs file systems on the user's system if I can avoid it. Obviously I can do df | grep tmpfs and use whatever mount that returns, but I was hoping for something a bit more elegant. Is it possible to write to a pseudo terminal or maybe to /proc somewhere?


Solution

  • You could try named pipes if the child process accepts non-seekable files. The content of a named pipe doesn't touch disk.