Signal.trap( signal ) {| | block } â obj
Specifies the handling of signals. The first parameter is a signal name (a string such as âSIGALRM'', âSIGUSR1'', and so on) or a signal number. The characters âSIG'' may be omitted from the signal name. The command or block specifies code to be run when the signal is raised. If the command is the string âIGNORE'' or âSIG_IGN'', the signal will be ignored. If the command is âDEFAULT'' or âSIG_DFL'', the Ruby's default handler will be invoked. If the command is âEXIT'', the script will be terminated by the signal. If the command is âSYSTEM_DEFAULT'', the operating system's default handler will be invoked. Otherwise, the given command or block will be run. The special signal name âEXIT'' or signal number zero will be invoked just prior to program termination. trap returns the previous handler for the given signal.
Signal.trap(0, proc { puts "Terminating: #{$$}" }) Signal.trap("CLD") { puts "Child died" } fork && Process.wait
produces:
Terminating: 27461 Child died Terminating: 27460
Please login to continue.