enum Signal
¶
Safely handle inter-process signals on POSIX systems.
Signals are dispatched to the event loop and later processed in a dedicated fiber. Some received signals may never be processed when the program terminates.
puts "Ctrl+C still has the OS default action (stops the program)"
sleep 3
Signal::INT.trap do
puts "Gotcha!"
end
puts "Ctrl+C will be caught from now on"
sleep 3
Signal::INT.reset
puts "Ctrl+C is back to the OS default action"
sleep 3
Note: - An uncaught exception in a signal handler is a fatal error.
Members¶
HUP = 1
¶
1
INT = 2
¶
2
QUIT = 3
¶
3
ILL = 4
¶
4
TRAP = 5
¶
5
IOT = 6
¶
6
ABRT = 6
¶
6
FPE = 8
¶
8
KILL = 9
¶
9
BUS = 7
¶
7
SEGV = 11
¶
11
SYS = 31
¶
31
PIPE = 13
¶
13
ALRM = 14
¶
14
TERM = 15
¶
15
URG = 23
¶
23
STOP = 19
¶
19
TSTP = 20
¶
20
CONT = 18
¶
18
CHLD = 17
¶
17
TTIN = 21
¶
21
TTOU = 22
¶
22
IO = 29
¶
29
XCPU = 24
¶
24
XFSZ = 25
¶
25
VTALRM = 26
¶
26
USR1 = 10
¶
10
USR2 = 12
¶
12
WINCH = 28
¶
28
PWR = 30
¶
30
STKFLT = 16
¶
16
UNUSED = 31
¶
31
Methods¶
#ignore : Nil
¶
: Nil
Clears the handler for this signal and prevents the OS default action.
Note that trying to ignore CHLD
will actually set the default crystal
handler that monitors and reaps child processes. This prevents zombie
processes and is required by Process#wait
for example.
#reset : Nil
¶
: Nil
Resets the handler for this signal to the OS default.
Note that trying to reset CHLD
will actually set the default crystal
handler that monitors and reaps child processes. This prevents zombie
processes and is required by Process#wait
for example.
#trap(&handler : Signal -> ) : Nil
¶
(&handler : Signal -> ) : Nil
Sets the handler for this signal to the passed function.
After executing this, whenever the current process receives the corresponding signal, the passed function will be called (instead of the OS default). The handler will run in a signal-safe fiber thought the event loop; there is no limit to what functions can be called, unlike raw signals that run on the sigaltstack.
Note that CHLD
is always trapped and child processes will always be reaped
before the custom handler is called, hence a custom CHLD
handler must
check child processes using Process.exists?
. Trying to use waitpid with a
zero or negative value won't work.