title: how to turn program into deamon program
body: <p>I sometimes write program like this to process offline data:</p>
  
  <pre><code>load_model() //this may cost lots of time
  while(cin &gt;&gt; inputs)
  {
      result = process_input(inputs)
      cout &lt;&lt; result
  }
  release_model()
  </code></pre>
  
  <p>This works fine if I only have to process offline data. However, when the data comes one by one I am in trouble. Since I have to load the model everytime which is time consuming.</p>
  
  <p>I wonder if there is any way to CONVERT this program into a service WITHOUT modify the program itself. For example, I can redirect the cin and cout to two named pipes:</p>
  
  <pre><code>program &lt; namedpipe_in &gt; namedpipe_out
  </code></pre>
  
  <p>The I can put the inputs into the namedpipe_in like this</p>
  
  <pre><code>cat input &gt; namedpipe_in
  </code></pre>
  
  <p>and read the result in another pipe:</p>
  
  <pre><code>cat namedpipe_out
  </code></pre>
  
  <p>However, this solution will not work since once I cat something to the namedpipe_in, the pipe will be close after cat operation and the program exits.</p>
  
  <p>My question is how to fix this problem and make the pipes looks more like a queue instead of a memory buffer.</p>
  
  <p>Thanks for your time reading.</p>