Text descriptions of signal codes?

A

allenjo5

Is there as easy a way to get the textual description of a process
signal code in perl as there is to get the textual description of a
system call error code? For instance, for an errno of 24, just set $!
to 24 and use it as a string:

$ perl -le '$!=24; print $!'
The process file table is full.

Is there something equivalent for getting the text meaning of signal
code 24 (SIGXCPU) without having to parse signal.h? Yeah I can do
that readily enough, but was expecting perl to provide an easier
method. So far, I haven't found the trick.
 
A

allenjo5

A. Sinan Unur said:
use Config;
use List::MoreUtils 'first_index';

my $sig_idx = first_index { $_ == 24 } split / /, $Config{sig_num};
if ( $sig_idx >= 0 ) {
my @sig_name = split / /, $Config{sig_name};
print $sig_name[$sig_idx], "\n";
}

Yes, that will get me "SIGXCPU" but I was looking for an english
description like "cpu time limit exceeded". Sorry if I wasn't clear
about that. I guess parsing signal.h isn't so bad...
 
B

Ben Morrow

Quoth (e-mail address removed):
A. Sinan Unur said:
use Config;
use List::MoreUtils 'first_index';

my $sig_idx = first_index { $_ == 24 } split / /, $Config{sig_num};
if ( $sig_idx >= 0 ) {
my @sig_name = split / /, $Config{sig_name};
print $sig_name[$sig_idx], "\n";
}

Yes, that will get me "SIGXCPU" but I was looking for an english
description like "cpu time limit exceeded". Sorry if I wasn't clear
about that. I guess parsing signal.h isn't so bad...

At least on my system, this stuff isn't in signal.h. You need to read
the sys_siglist array. I wrote a tiny XS module to do just that, which I
guess I could upload to CPAN if that would help you...

A major problem (IMHO) is that there is no way of i18ning[0] these things.

Ben
 
A

anno4000

Is there as easy a way to get the textual description of a process
signal code in perl as there is to get the textual description of a
system call error code? For instance, for an errno of 24, just set $!
to 24 and use it as a string:

$ perl -le '$!=24; print $!'
The process file table is full.

Is there something equivalent for getting the text meaning of signal
code 24 (SIGXCPU) without having to parse signal.h? Yeah I can do
that readily enough, but was expecting perl to provide an easier
method. So far, I haven't found the trick.

The Config module has the table you want. Adapted from "perldoc
perlipc":

use Config;
defined $Config{sig_name} || die "No sigs?";

my ( @signame, %signo);
my $i = 0;
foreach my $name ( split(' ', $Config{sig_name}) ) {
$signo{$name} = $i;
$signame[$i] = $name;
$i++;
}

Anno
 
A

allenjo5

Ben said:
At least on my system, this stuff isn't in signal.h. You need to read
the sys_siglist array. I wrote a tiny XS module to do just that, which I
guess I could upload to CPAN if that would help you...

Hmmm, yes, I guess access to the sys_siglist array is what I want.
There's also the psignal() system call that provides the same info.
Both seem to be in the standard C library (on AIX anyway). I don't
want it bad enough to be the sole reason that you upload such a CPAN
module, but if you did I wouldn't mind :)

John.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top