Event::signal#

📦 max

A signal watcher: an event when the process receives a signal.

Event->signal(%attributes) (or Event::signal->new(...)) takes the shared attributes of Event::Watcher and signal. A signal watcher repeats; its default priority is PRIO_HIGH. It refuses to start without a callback or a signal.

The signal handler only counts arrivals. The counts become events when the loop next looks (Event::queue_pending, which loop, sweep and one_event call), so signals can be handled later than, and out of order with, other events; several arrivals of a signal in between make one event whose hits is their number. The watchers that receive the event are the ones active when the counts are collected, not when the signal arrived.

A signal is handled either through %SIG or by Event, not both: while at least one watcher for it is active, Event’s handler is installed directly, without %SIG; when the last one stops, the signal is set back to its default action.

Synopsis#

use Event;

Event->signal(signal => 'HUP', cb => sub { reload_config() });
Event->signal(signal => 'INT', cb => sub { Event::unloop_all() });
Event::loop();

Functions#

Attributes#

signal#

The signal, by its name without SIG ('INT', 'HUP'), as the keys of %SIG; it is returned under its main name. An unknown name dies “Unrecognized signal ‘NAME’”, and a signal that cannot be caught (KILL, STOP) dies “Signal ‘NAME’ cannot be caught”. Changing it moves an active watcher to the new signal.