traping signals

B

bfay

In a script, I trap the interrupt and quit signals. I would like all
the other signals to be ignored. Is there a simple way to do it?

Thanks,
Bernard
 
M

Mark Clements

In a script, I trap the interrupt and quit signals. I would like all
the other signals to be ignored. Is there a simple way to do it?

Thanks,
Bernard
perldoc sigtrap
perldoc perlipc

Mark
 
C

Charles DeRykus

In a script, I trap the interrupt and quit signals. I would like all
the other signals to be ignored. Is there a simple way to do it?

Not really. If Unix-based and kill(1) supports -l , you
could grab the list and set the other signals to ignore:

{ local $SIG{INT} = sub my_int_catcher {...};
local $SIG{QUIT} = sub my_quit_catcher {...};
# test kill(1) for -l option ...
# grab signal list if -l available...
local $SIG{$_} = 'IGNORE' for @signal_list;
}

of course SIGKILL is uncatchable. Also, in some cases
you might be better off blocking signals rather than
ignoring them ('Perl Cookbook' has an example of how).

hth,
 
C

Christopher Nehren

Not really. If Unix-based and kill(1) supports -l , you
could grab the list and set the other signals to ignore:

[non-portable code snipped]

Instead of giving platform-specific code that returns tainted data, why
not just use the example given in perlipc?

I quote:

The names of the signals are the ones listed out by "kill -l" on
your system, or you can retrieve them from the Config module. Set up an
@signame list indexed by number to get the name and a %signo table
indexed by name to get the number:

use Config;
defined $Config{sig_name} || die "No sigs?";
foreach $name (split(' ', $Config{sig_name})) {
$signo{$name} = $i;
$signame[$i] = $name;
$i++;
}

End quote.

Best Regards,
Christopher Nehren
 
C

Charles DeRykus

Not really. If Unix-based and kill(1) supports -l , you
could grab the list and set the other signals to ignore:

[non-portable code snipped]

Instead of giving platform-specific code that returns tainted data, why
not just use the example given in perlipc?

I quote:

The names of the signals are the ones listed out by "kill -l" on
your system, or you can retrieve them from the Config module. Set up an
@signame list indexed by number to get the name and a %signo table
indexed by name to get the number:

use Config;
defined $Config{sig_name} || die "No sigs?";
foreach $name (split(' ', $Config{sig_name})) {
$signo{$name} = $i;
$signame[$i] = $name;
$i++;
}

Um, I stated if "Unix-based" and the snippage included:

# test kill(1) for -l option ...
# grab signal list if -l available...

Moreover, there was actually no 'non-portable' code since
I didn't explain how to 'test and grab'. I'd agree though
Config would be the preferable method for generating that
signal list.
 

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,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top