title: How to create a customized file descriptor on linux
body: <p>I would like to create a file whose descriptor would have some customizable behavior. In particular, I'd like to create a file descriptor, which, when written to, would prefix every line, with name of the process and pid (and maybe time), but I can imagine it can be useful to do other things.</p>
  
  <p>I don't want to alter the writing program - for one thing, I want it to work for all programs on my system, even shell/perl/etc. scripts, and it would be impractical if not impossible to change the source code of everything.</p>
  
  <p>Note that pipes wouldn't do in this case, because when the writing process <code>fork()</code>s, the newly created child shares the fd and is indistinguishable from its parent by the reading end of the pipe.</p>
  
  <p>There are approaches which would do, but I think they are rather clumsy:</p>
  
  <ol>
  <li>Create a kernel module that will create such fds. For example, you could open some <code>/dev/customfd</code> and then instruct the module to do some transformation etc. or send data to userspace or socket etc.</li>
  <li>Use LD_PRELOAD that will override the fd manipulation functions and do these kinds of things on the "special" fd.</li>
  </ol>
  
  <p>However, both of these approaches are quite laborious, so I would like to know if there is a better way, or any infrastructure (like off-the-shelf libraries) that would help.</p>
  
  <p>I'd prefer a solution which doesn't involve kernel changes, but I'm ready to accept them if necessary.</p>
  
  <p>Just an idea: would FUSE be an answer?</p>