Skip to content

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

INT = 2

QUIT = 3

ILL = 4

TRAP = 5

IOT = 6

ABRT = 6

FPE = 8

KILL = 9

BUS = 7

SEGV = 11

SYS = 31

PIPE = 13

ALRM = 14

TERM = 15

URG = 23

STOP = 19

TSTP = 20

CONT = 18

CHLD = 17

TTIN = 21

TTOU = 22

IO = 29

XCPU = 24

XFSZ = 25

VTALRM = 26

USR1 = 10

USR2 = 12

WINCH = 28

PWR = 30

STKFLT = 16

UNUSED = 31

Methods

#abrt?

View source

#alrm?

View source

#bus?

View source

#chld?

View source

#cont?

View source

#fpe?

View source

#hup?

View source

#ignore : 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.

View source

#ill?

View source

#int?

View source

#iot?

View source

#kill?

View source

#pipe?

View source

#pwr?

View source

#quit?

View source

#reset : 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.

View source

#segv?

View source

#stkflt?

View source

#stop?

View source

#sys?

View source

#term?

View source

#trap(&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.

View source

#trap?

View source

#tstp?

View source

#ttin?

View source

#ttou?

View source

#unused?

View source

#urg?

View source

#usr1?

View source

#usr2?

View source

#vtalrm?

View source

#winch?

View source

#xcpu?

View source

#xfsz?

View source