In Proc§
See primary documentation in context for method signal
method signal(Proc:)
Returns the signal number with which the external process was killed, or 0
or an undefined value otherwise.
In Supply§
See primary documentation in context for sub signal
sub signal(*, : = )
Creates a supply for the Signal enums (such as SIGINT) specified, and an optional :scheduler
parameter. Any signals received, will be emitted on the supply. For example:
signal(SIGINT).tap( );
would catch Control-C, thank you, and then exit.
To go from a signal number to a Signal, you can do something like this:
signal(Signal(2)).tap( -> );
The list of supported signals can be found by checking Signal::.keys
(as you would any enum). For more details on how enums work see enum.
Note: Rakudo versions up to 2018.05 had a bug due to which numeric values of signals were incorrect on some systems. For example, Signal(10)
was returning SIGBUS
even if it was actually SIGUSR1
on a particular system. That being said, using signal(SIGUSR1)
was working as expected on all Rakudo versions except 2018.04, 2018.04.1 and 2018.05, where the intended behavior can be achieved by using signal(SIGBUS)
instead. These issues are resolved in Rakudo releases after 2018.05.
In Kernel§
See primary documentation in context for method signal
multi method signal(Kernel: Str --> Int)multi method signal(Kernel: Signal \signal --> Int)multi method signal(Kernel: Int \signal --> Int)
Instance method returning the Signal
numeric code for a given name for the Kernel object.
say .signal("INT"); # OUTPUT: «2»
In Lock::ConditionVariable§
See primary documentation in context for method signal
method signal()
If and only if there are any threads that have previously waited on the condition variable, it unblocks at least one of them. Let's see how it works in this example:
constant ITEMS = 100;for 1..15 ->
We are repeating 15 times the same operation: start 100 threads, every one of which modify a single element in an array. We protect
the modification of a global variable, $done
, and use signal
to wake a up another thread to do its thing. This outputs the first elements of the generated arrays.