Lähettäjä: Bjarke Bruun <bbj@swooplinux.org>
Aihe: Re: TCPSocket hangs after ctrl-c>
> > fork {
>
> Why you don't use a thread, with a block local variable for @sThis is just a "test" for me. It's not (yet anyway) in progress of
beeing published... the rfc is large for startes, but the fork, IMHO,
has less footprint than threads and threads in ruby are only threads
inside the ruby process so the difference is the same until Matz et.
al. implements native threads for ruby (which I'm waiting for :-))The problem is not the local socket that is talking to the client it's
the main socket that hangs if I don't use "kill -9" and I would like to
find a way to fix that... "E S" has a point, but I'm new to Ruby and
don't quite know where to get info on usage of the
Signal#trap and Process#abort right now. Always glad to learn more but
from scratch is hard, if you remember
http://www.ruby-doc.org/ is your friend Look for Process and
Signal in the Core API.
You could do something like this (use whatever signals):
# ...
def initialize
# ...
Signal.trap "TERM" do
puts "Bringing #{$0} down..."
shutdown
puts "...down."
end
@child = fork do
# Propagated
Signal.trap "TERM" do
# Shutdown procedures, finish read etc.
puts "...reader terminated..."
end
# ...
end
def shutdown
# Send a signal to the child
Process.kill "TERM", @child
Process.wait @child
puts "...main process terminated..."
end
I'm looking for something like this
$ ./rsmtp.rb # the name of the server script
and then be able to press <ctrl-c> without having the socket hanging for
some 30 seconds before I can start the script again. I had a similar
experience in school a long time ago in C++ but I can't remember the
code I wrote back then to overcome this problem... and I don't have the
code anymore FYI.I'm looking in "Programming Ruby: The Progmatic Programmer's Guide" with
no luck as to set up a trap for the script if it receives (SIG)KILL
signal - where to look?
E
···
On Sunday 16 January 2005 16:03, ts wrote: