NAME

Signal::Pipe - Self pipes for signal handling

VERSION

version 0.001

SYNOPSIS

use POSIX 'SIGINT';
use Signal::Pipe 'selfpipe';
my $fh = selfpipe(SIGINT);
add_handler($fh, sub {
  if (sysread($fh, my $buf, 128)) {
    # handle signal
  }
});

FUNCTIONS

selfpipe($signo)

This function sets a signal handler $signo for the process that will write one byte for each handled signal to the file handle that is returned by this function. When the handle becomes readable, you want to drain the filehandle using sysread. The handle is automatically made non-blocking, and signals may be squashed.

Note that there may only be one such handle for each signal in the process, and that the signal delivery is mostly shared between different threads in the same process.

SEE ALSO

  • Async::Interrupt

    A module that can do a similar thing (and some other things).

  • Linux::FD::Signal

    A linux specific module that allows one to pass much more information.

AUTHOR

Leon Timmermans <leont@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2015 by Leon Timmermans.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.