title: How to run multiple ruby daemons and handle input and output of each daemon?
body: <p>Here's the code:</p>
  
  <pre><code>while 1
      input = gets
      puts input
  end
  </code></pre>
  
  <p>Here's what I want to do but I have no idea how to do it:
  I want to create multiple instances of the code to run in the background and be able to pass input to a specific instance. </p>
  
  <p>Q1: How do I run multiple instances of the script in the background?</p>
  
  <p>Q2: How do I refer to an individual instance of the script so I can pass input to the instance (Q3)?</p>
  
  <p>Q3: The script is using the cmd "gets" to take input, how would I pass input into an indivdual's script's gets?</p>
  
  <p>e.g</p>
  
  <p>Let's say I'm running threes instances of the code in the background and I refer to the instance as #1, #2, and #3 respectively. 
  I pass "hello" to #1, #1 puts "hello" to the screen. 
  Then I pass "world" to #3 and #3 puts "hello" to the screen. </p>
  
  <p>Thanks!</p>
  
  <p>UPDATE:
  Answered my own question. Found this awesome tut: <a href="http://rubylearning.com/satishtalim/ruby_threads.html" rel="nofollow">http://rubylearning.com/satishtalim/ruby_threads.html</a> and resource here: <a href="http://www.ruby-doc.org/core/classes/Thread.html#M000826" rel="nofollow">http://www.ruby-doc.org/core/classes/Thread.html#M000826</a>.</p>
  
  <pre><code>puts Thread.main
  
  x = Thread.new{loop{puts 'x'; puts gets; Thread.stop}}
  y = Thread.new{loop{puts 'y'; puts gets; Thread.stop}}
  z = Thread.new{loop{puts 'z'; puts  gets; Thread.stop}}
  
  while x.status != "sleep" and y.status != "sleep" and z.status !="sleep"
      sleep(1)
  end
  
  Thread.list.each {|thr| p thr }
  
  x.run
  x.join
  </code></pre>
  
  <p>Thank you for all the help guys! Help clarified my thinking. </p>