Method: Process.kill
- Defined in:
- process.c
.kill(signal, pid, ...) ⇒ Integer
Sends the given signal to the specified process id(s) if pid is positive. If pid is zero, signal is sent to all processes whose group ID is equal to the group ID of the process. If pid is negative, results are dependent on the operating system. signal may be an integer signal number or a POSIX signal name (either with or without a SIG prefix). If signal is negative (or starts with a minus sign), kills process groups instead of processes. Not all signals are available on all platforms. The keys and values of Signal.list are known signal names and numbers, respectively.
pid = fork do
Signal.trap("HUP") { puts "Ouch!"; exit }
# ... do some work ...
end
# ...
Process.kill("HUP", pid)
Process.wait
produces:
Ouch!
If signal is an integer but wrong for signal, Errno::EINVAL or RangeError will be raised. Otherwise unless signal is a String or a Symbol, and a known signal name, ArgumentError will be raised.
Also, Errno::ESRCH or RangeError for invalid pid, Errno::EPERM when failed because of no privilege, will be raised. In these cases, signals may have been sent to preceding processes.
8118 8119 8120 8121 8122 |
# File 'process.c', line 8118
static VALUE
proc_rb_f_kill(int c, const VALUE *v, VALUE _)
{
return rb_f_kill(c, v);
}
|