Module: Signal

Defined in:
signal.c

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.listHash

Returns a list of signal names mapped to the corresponding underlying signal numbers.

Signal.list #=> “ALRM”=>14, “BUS”=>7, “CHLD”=>17, “CLD”=>17, “CONT”=>18, “FPE”=>8, “HUP”=>1, “ILL”=>4, “INT”=>2, “IO”=>29, “IOT”=>6, “KILL”=>9, “PIPE”=>13, “POLL”=>29, “PROF”=>27, “PWR”=>30, “QUIT”=>3, “SEGV”=>11, “STOP”=>19, “SYS”=>31, “TERM”=>15, “TRAP”=>5, “TSTP”=>20, “TTIN”=>21, “TTOU”=>22, “URG”=>23, “USR1”=>10, “USR2”=>12, “VTALRM”=>26, “WINCH”=>28, “XCPU”=>24, “XFSZ”=>25

Returns:

  • (Hash)


928
929
930
931
932
933
934
935
936
937
938
# File 'signal.c', line 928

static VALUE
sig_list()
{
    VALUE h = rb_hash_new();
    struct signals *sigs;

    for (sigs = siglist; sigs->signm; sigs++) {
  rb_hash_aset(h, rb_str_new2(sigs->signm), INT2FIX(sigs->signo));
    }
    return h;
}

.trap(signal, proc) ⇒ Object .trap(signal) {|| ... } ⇒ Object

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

Overloads:



881
882
883
# File 'signal.c', line 881

static VALUE
sig_trap(argc, argv)
int argc;

Instance Method Details

#listHash (private)

Returns a list of signal names mapped to the corresponding underlying signal numbers.

Signal.list #=> “ALRM”=>14, “BUS”=>7, “CHLD”=>17, “CLD”=>17, “CONT”=>18, “FPE”=>8, “HUP”=>1, “ILL”=>4, “INT”=>2, “IO”=>29, “IOT”=>6, “KILL”=>9, “PIPE”=>13, “POLL”=>29, “PROF”=>27, “PWR”=>30, “QUIT”=>3, “SEGV”=>11, “STOP”=>19, “SYS”=>31, “TERM”=>15, “TRAP”=>5, “TSTP”=>20, “TTIN”=>21, “TTOU”=>22, “URG”=>23, “USR1”=>10, “USR2”=>12, “VTALRM”=>26, “WINCH”=>28, “XCPU”=>24, “XFSZ”=>25

Returns:

  • (Hash)


928
929
930
931
932
933
934
935
936
937
938
# File 'signal.c', line 928

static VALUE
sig_list()
{
    VALUE h = rb_hash_new();
    struct signals *sigs;

    for (sigs = siglist; sigs->signm; sigs++) {
  rb_hash_aset(h, rb_str_new2(sigs->signm), INT2FIX(sigs->signo));
    }
    return h;
}

#trap(signal, proc) ⇒ Object (private) #trap(signal) {|| ... } ⇒ Object (private)

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

Overloads:



881
882
883
# File 'signal.c', line 881

static VALUE
sig_trap(argc, argv)
int argc;