The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

POSIX::1003::Signals - POSIX using signals

INHERITANCE

 POSIX::1003::Signals
   is a POSIX::1003

SYNOPSIS

  use POSIX::1003::Signals qw(:functions SIGPOLL SIGHUP);
  sigaction($signal, $action, $oldaction);
  sigpending($sigset);
  sigprocmask($how, $sigset, $oldsigset)
  sigsuspend($signal_mask);

  kill SIGPOLL//SIGHUP, $$;

DESCRIPTION

This manual page explains the access to the POSIX sigaction functions and its relatives. This module uses two helper objects: POSIX::SigSet and POSIX::SigAction.

FUNCTIONS

Standard POSIX

kill(SIGNAL, PROCESS)

Simply "kill" in perlfunc.

Be warned the order of parameters is reversed in the kill exported by POSIX!

  CORE::kill($signal, $pid);
  ::Signals::kill($signal, $pid);
  POSIX::kill($pid, $signal);
raise(SIGNAL)

Send a signal to the executing process.

sigaction(SIGNAL, ACTION, [OLDACTION])

Detailed signal management. The signal must be a number (like SIGHUP), not a string (like "SIGHUP"). The action and oldaction arguments are POSIX::SigAction objects. Returns undef on failure.

Consult your system's sigaction manpage for details. See also POSIX::SigRt.

If you use the SA_SIGINFO flag, the signal handler will in addition to the first argument (the signal name) also receive a second argument: a hash reference, inside which are the following keys with the following semantics, as defined by POSIX/SUSv3:

  signo   the signal number
  errno   the error number
  code    if this is zero or less, the signal was sent by
          a user process and the uid and pid make sense,
          otherwise the signal was sent by the kernel

The following are also defined by POSIX/SUSv3, but unfortunately not very widely implemented:

  pid     the process id generating the signal
  uid     the uid of the process id generating the signal
  status  exit value or signal for SIGCHLD
  band    band event for SIGPOLL

A third argument is also passed to the handler, which contains a copy of the raw binary contents of the siginfo structure: if a system has some non-POSIX fields, this third argument is where to unpack() them from.

Note that not all siginfo values make sense simultaneously (some are valid only for certain signals, for example), and not all values make sense from Perl perspective.

signal(SIGNAL, (CODE|'IGNORE'|'DEFAULT'))

Set the CODE (subroutine reference) to be called when the SIGNAL appears. See "%SIG" in perlvar.

   signal(SIGINT, \&handler);
   $SIG{SIGINT} = \&handler;  # same
sigpending(SIGSET)

Examine signals that are blocked and pending. This uses POSIX::SigSet objects for the sigset argument. Returns undef on failure.

sigprocmask(HOW, SIGSET, [OLDSIGSET])

Change and/or examine calling process's signal mask. This uses POSIX::SigSet objects for the sigset and oldsigset arguments. Returns undef on failure.

Note that you can't reliably block or unblock a signal from its own signal handler if you're using safe signals. Other signals can be blocked or unblocked reliably.

sigsuspend(SIGSET)

Install a signal mask and suspend process until signal arrives. This uses POSIX::SigSet objects for the signal_mask argument. Returns undef on failure.

These functions are implemened in POSIX.xs

CONSTANTS

Signal names

 SIGABRT SIGALRM SIGCHLD SIGCONT SIGFPE SIGHUP SIGILL SIGINT SIGKILL
 SIGPIPE SIGRTMIN SIGRTMAX SIGQUIT SIGSEGV SIGSTOP SIGTERM SIGTSTP
 SIGTTIN SIGTTOU SIGUSR1 SIGUSR2 SIGBUS SIGPOLL SIGPROF SIGSYS SIGTRAP
 SIGURG SIGVTALRM SIGXCPU SIGXFSZ SIG_BLOCK SIG_DFL SIG_ERR SIG_IGN
 SIG_SETMASK SIG_UNBLOCK

Signals actions

 SA_NOCLDSTOP SA_NOCLDWAIT SA_NODEFER SA_ONSTACK SA_RESETHAND
 SA_RESTART SA_SIGINFO

SEE ALSO

This module is part of POSIX-1003 distribution version 0.04, built on December 22, 2011. Website: http://perl.overmeer.net. The code is based on POSIX, which is released with Perl itself.

COPYRIGHTS

Copyrights of the perl code and the related documentation by 2011 by Mark Overmeer. For other contributors see ChangeLog.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See http://www.perl.com/perl/misc/Artistic.html