From: bob@... (Bob Proulx) Date: 2007-09-12T13:04:18+09:00 Subject: Re: Threads and daemons Cd Cd wrote: > Okay, bear with this. When I copied the program, I forgot part of it -( > Here is the entire thing. I think your "party" process is exiting very quickly. I think there is a problem when it is run like this and since the output from the program is being discarded you are not seeing it. > #!/usr/local/bin/ruby > > threads=[] > > 4.times do |i| > threads[i]=Thread.new do > %x{/usr/local/bin/party} Ouch. Please think about indention here. That line should be indented one more level than the previous line. And an indention of eight is pretty big for one level of indention. > end > end > > threads.each{|thr| thr.join} The %x{} is executing the party program but any output is being discarded. Personally I think using 'system' is better in that case because it does not need to collect the output at all. Using %x{...} or using `...` means that ruby needs to wait until the process has terminated and then do something with the string of output collected. In this case the do something is nothing and it is garbage collected but then in that case I think it is better not to collect it at all. Whenever I see `...` or %x{...} without it being an assignment it triggers me to question it. > So do I move join into the do/end block? Try this modification to your program: #!/usr/bin/env ruby threads = [] 4.times do threads << Thread.new do output = %x{/usr/local/bin/party} puts "party output: " + output end end threads.each{|thr| thr.join} exit 0 Is there any output from your "party" program? I am hoping there will be errors shown there that were not displayed before that will lead you to the problem. When I create a simply /tmp/testdaemon script like this: #!/usr/bin/env ruby puts "Hello from testdaemon." exit 0 And then run your example like this: #!/usr/bin/env ruby threads = [] 4.times do threads << Thread.new do output = %x{/tmp/testdaemon} puts "party output: " + output end end threads.each{|thr| thr.join} exit 0 Then I see this output: party output: Hello from testdaemon. party output: Hello from testdaemon. party output: Hello from testdaemon. party output: Hello from testdaemon. Bob