There are several ways to do this. You saw a method using POSIX , which I usually avoid, because by default it imports a huge number of characters (about six hundred) into the current package. Even if you restrict it to the names you need for this, by writing
use POSIX ':signal_h';
there are still about fifty names left. It is also a trial and error issue for detecting a signal name with its number using this module.
You can also build a table of signals that your Perl has created using the Config module, which exports a list of signal names and their corresponding numbers to $Config{sig_name} and $Config{sig_num} .
use strict; use warnings; use Config '%Config'; my @sig_names; @sig_names[ split ' ', $Config{sig_num} ] = split ' ', $Config{sig_name}; printf "Signal number 2 is %s\n", $sig_names[2];
Output
Signal number 2 is INT
Or you can use the IPC::Signal module, which conveniently transfers all this
use strict; use warnings; use IPC::Signal 'sig_name'; printf "Signal number 2 is %s\n", sig_name(2);
Output
Signal number 2 is INT
source share