View on
Mark Overmeer > POSIX-1003-0.95.1 > POSIX::1003::Signals



Annotate this POD


New  1
Open  0
View/Report Bugs
Module Version: 0.95.1   Source   Latest Release: POSIX-1003-0.99_07


POSIX::1003::Signals - POSIX using signals


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

  kill SIGPOLL//SIGHUP, $$;

  use POSIX::1003::Signals '%signals';
  my $number = $signals{SIGHUP};
  $signals{SIGNEW} = $number;


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.


These functions are implemened in POSIX.xs

Standard POSIX


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);

Send a signal to the executing process.


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.

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.


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

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

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.


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


Returns a string reprentation of the SIGNAL. When the SIGNAL is unknown, a standard string is returned (never undef)



Returns a list with all known sigaction names, unsorted.


Returns a list with all known signal names, unsorted.



This exported variable is a (tied) HASH which maps SIG* and SA_* names to their numbers.

Export tag :signals

The following constants are exported, shown here with the values discovered during installation of this module:

  SIGABRT    6          SIGKILL    9          SIGTERM    15
  SIGALRM    14         SIGPIPE    13         SIGTRAP    5
  SIGBUS     7          SIGPOLL    29         SIGTSTP    20
  SIGCHLD    17         SIGPROF    27         SIGTTIN    21
  SIGCLD     17         SIGPWR     30         SIGTTOU    22
  SIGCONT    18         SIGQUIT    3          SIGURG     23
  SIGFPE     8          SIGRTMAX   64         SIGUSR1    10
  SIGHUP     1          SIGRTMIN   34         SIGUSR2    12
  SIGILL     4          SIGSEGV    11         SIGVTALRM  26
  SIGINT     2          SIGSTKFLT  16         SIGWINCH   28
  SIGIO      29         SIGSTOP    19         SIGXCPU    24
  SIGIOT     6          SIGSYS     31         SIGXFSZ    25

Export tag :actions

  SA_NOCLDSTOP  1                 SA_ONSTACK    134217728
  SA_NOCLDWAIT  2                 SA_RESETHAND  2147483648
  SA_NODEFER    1073741824        SA_RESTART    268435456
  SA_NOMASK     1073741824        SA_SIGINFO    4


This module is part of POSIX-1003 distribution version 0.95.1, built on August 26, 2013. Website: The code is based on POSIX, which is released with Perl itself. See also POSIX::Util for additional functionality.


Copyrights 2011-2013 on the perl code and the related documentation 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

syntax highlighting: