home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


16.13. Listing Available Signals

Problem

You want to know the signals your operating system provides.

Solution

If your shell has a built-in kill -l command, use it:

% kill -l




HUP INT QUIT ILL TRAP ABRT BUS FPE KILL USR1 SEGV USR2 PIPE 








ALRM TERM CHLD CONT STOP TSTP TTIN TTOU URG XCPU XFSZ VTALRM 








PROF WINCH POLL PWR



Or using just Perl, print the keys in %SIG if you have release 5.004 or later:

% perl -e 'print join(" ", keys %SIG), "\n"'




XCPU ILL QUIT STOP EMT ABRT BUS USR1 XFSZ TSTP INT IOT USR2 INFO TTOU








ALRM KILL HUP URG PIPE CONT SEGV VTALRM PROF TRAP IO TERM WINCH CHLD








FPE TTIN SYS



Before version 5.004, you had to use the Config module:

% perl -MConfig -e 'print $Config{sig_name}'




ZERO HUP INT QUIT ILL TRAP ABRT EMT FPE KILL BUS SEGV SYS PIPE ALRM








TERM URG STOP TSTP CONT CHLD TTIN TTOU IO XCPU XFSZ VTALRM PROF WINCH








INFO USR1 USR2 IOT



Discussion

If your version of Perl is before 5.004, you have to use signame and signo in Config to find the list of available signals, since keys %SIG wasn't implemented then.

The following code retrieves by name and number the available signals from Perl's standard Config.pm module. Use @signame indexed by number to get the signal name, and %signo indexed by name to get the signal number.

use Config;
defined $Config{sig_name} or die "No sigs?";
$i = 0;                     # Config prepends fake 0 signal called "ZERO".
foreach $name (split(' ', $Config{sig_name})) {
    $signo{$name} = $i;
    $signame[$i] = $name;
    $i++;
}

See Also

The documentation for the standard Config module, also in Chapter 7 of Programming Perl ; the "Signals" sections in Chapter 6 of Programming Perl and in perlipc (1)