From: Michael Malone Date: 2009-03-16T06:49:49+09:00 Subject: Re: Keep thread in memory Craig Williams wrote: > Hi, > > I'm writing a simple UDP listening server. It works great using this > > PORT = 1234 > server = UDPSocket.open > server.bind("127.0.0.1", PORT) > > server_thread = Thread.start(server) do |server| > 100.times { #do something } > end > > server_thread.join > > The above was based off some code from the Ruby 1.9 book - I have a problem > now trying to take it a step further. > > How do I get the above to run permanently or until some other condition > besides (100) is reached? > > When I run this on my remote server over SSH it works but if I ctrl-z or > exit ssh, the process seems to be in memory but isn't actually working. I'd > like to run it and have it go into memory until it is killed and return me > to the ssh command. > > I tried leaving off the server_thread.join but then it just quits. Could > someone explain exactly what Thread.start is doing here. > > thanks! > -c > > It does exactly what you think it will do. It starts a thread, runs the block and exits when the block is completed. If you want it to wait around for things to happen, like something being fed down a socket, you just need to make a call to an async function, like IO.read(server) which will wait around until there is something to read. I can't explain why your process is still in memory. To me, it should have exited and dropped off the face of the planet. ======================================================================= This email, including any attachments, is only for the intended addressee. It is subject to copyright, is confidential and may be the subject of legal or other privilege, none of which is waived or lost by reason of this transmission. If the receiver is not the intended addressee, please accept our apologies, notify us by return, delete all copies and perform no other act on the email. Unfortunately, we cannot warrant that the email has not been altered or corrupted during transmission. =======================================================================