Skip to content

Instantly share code, notes, and snippets.

@masak
Created March 23, 2009 09:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save masak/83484 to your computer and use it in GitHub Desktop.
Save masak/83484 to your computer and use it in GitHub Desktop.
------------------------------------------------------------ Kernel#trap
Signal.trap( signal, proc ) => obj
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 operating system's default handler
will be invoked. If the command is ``EXIT'', the script will be
terminated by the signal. 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment