{
    "mode": "perldoc",
    "parameter": "sigtrap",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/sigtrap/json",
    "generated": "2026-06-13T20:02:34Z",
    "synopsis": "use sigtrap;\nuse sigtrap qw(stack-trace old-interface-signals);  # equivalent\nuse sigtrap qw(BUS SEGV PIPE ABRT);\nuse sigtrap qw(die INT QUIT);\nuse sigtrap qw(die normal-signals);\nuse sigtrap qw(die untrapped normal-signals);\nuse sigtrap qw(die untrapped normal-signals\nstack-trace any error-signals);\nuse sigtrap 'handler' => \\&myhandler, 'normal-signals';\nuse sigtrap qw(handler myhandler normal-signals\nstack-trace error-signals);",
    "sections": {
        "NAME": {
            "content": "sigtrap - Perl pragma to enable simple signal handling\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use sigtrap;\nuse sigtrap qw(stack-trace old-interface-signals);  # equivalent\nuse sigtrap qw(BUS SEGV PIPE ABRT);\nuse sigtrap qw(die INT QUIT);\nuse sigtrap qw(die normal-signals);\nuse sigtrap qw(die untrapped normal-signals);\nuse sigtrap qw(die untrapped normal-signals\nstack-trace any error-signals);\nuse sigtrap 'handler' => \\&myhandler, 'normal-signals';\nuse sigtrap qw(handler myhandler normal-signals\nstack-trace error-signals);\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "The sigtrap pragma is a simple interface to installing signal handlers. You can have it install\none of two handlers supplied by sigtrap itself (one which provides a Perl stack trace and one\nwhich simply \"die()\"s), or alternately you can supply your own handler for it to install. It can\nbe told only to install a handler for signals which are either untrapped or ignored. It has a\ncouple of lists of signals to trap, plus you can supply your own list of signals.\n\nThe arguments passed to the \"use\" statement which invokes sigtrap are processed in order. When a\nsignal name or the name of one of sigtrap's signal lists is encountered a handler is immediately\ninstalled, when an option is encountered it affects subsequently installed handlers.\n",
            "subsections": []
        },
        "OPTIONS": {
            "content": "SIGNAL HANDLERS\nThese options affect which handler will be used for subsequently installed signals.\n\nstack-trace\nThe handler used for subsequently installed signals outputs a Perl stack trace to STDERR and\nthen tries to dump core. This is the default signal handler.\n\ndie The handler used for subsequently installed signals calls \"die\" (actually \"croak\") with a\nmessage indicating which signal was caught.\n\nhandler *your-handler*\n*your-handler* will be used as the handler for subsequently installed signals.\n*your-handler* can be any value which is valid as an assignment to an element of %SIG. See\nperlvar for examples of handler functions.\n\nSIGNAL LISTS\nsigtrap has a few built-in lists of signals to trap. They are:\n\nnormal-signals\nThese are the signals which a program might normally expect to encounter and which by\ndefault cause it to terminate. They are HUP, INT, PIPE and TERM.\n\nerror-signals\nThese signals usually indicate a serious problem with the Perl interpreter or with your\nscript. They are ABRT, BUS, EMT, FPE, ILL, QUIT, SEGV, SYS and TRAP.\n\nold-interface-signals\nThese are the signals which were trapped by default by the old sigtrap interface, they are\nABRT, BUS, EMT, FPE, ILL, PIPE, QUIT, SEGV, SYS, TERM, and TRAP. If no signals or signals\nlists are passed to sigtrap, this list is used.\n\nFor each of these three lists, the collection of signals set to be trapped is checked before\ntrapping; if your architecture does not implement a particular signal, it will not be trapped\nbut rather silently ignored.\n\nOTHER\nuntrapped\nThis token tells sigtrap to install handlers only for subsequently listed signals which\naren't already trapped or ignored.\n\nany This token tells sigtrap to install handlers for all subsequently listed signals. This is\nthe default behavior.\n\n*signal*\nAny argument which looks like a signal name (that is, \"/^[A-Z][A-Z0-9]*$/\") indicates that\nsigtrap should install a handler for that name.\n\n*number*\nRequire that at least version *number* of sigtrap is being used.\n",
            "subsections": []
        },
        "EXAMPLES": {
            "content": "Provide a stack trace for the old-interface-signals:\n\nuse sigtrap;\n\nDitto:\n\nuse sigtrap qw(stack-trace old-interface-signals);\n\nProvide a stack trace on the 4 listed signals only:\n\nuse sigtrap qw(BUS SEGV PIPE ABRT);\n\nDie on INT or QUIT:\n\nuse sigtrap qw(die INT QUIT);\n\nDie on HUP, INT, PIPE or TERM:\n\nuse sigtrap qw(die normal-signals);\n\nDie on HUP, INT, PIPE or TERM, except don't change the behavior for signals which are already\ntrapped or ignored:\n\nuse sigtrap qw(die untrapped normal-signals);\n\nDie on receipt one of an of the normal-signals which is currently untrapped, provide a stack\ntrace on receipt of any of the error-signals:\n\nuse sigtrap qw(die untrapped normal-signals\nstack-trace any error-signals);\n\nInstall myhandler() as the handler for the normal-signals:\n\nuse sigtrap 'handler', \\&myhandler, 'normal-signals';\n\nInstall myhandler() as the handler for the normal-signals, provide a Perl stack trace on\nreceipt of one of the error-signals:\n\nuse sigtrap qw(handler myhandler normal-signals\nstack-trace error-signals);\n",
            "subsections": []
        }
    },
    "summary": "sigtrap - Perl pragma to enable simple signal handling",
    "flags": [],
    "examples": [
        "Provide a stack trace for the old-interface-signals:",
        "use sigtrap;",
        "Ditto:",
        "use sigtrap qw(stack-trace old-interface-signals);",
        "Provide a stack trace on the 4 listed signals only:",
        "use sigtrap qw(BUS SEGV PIPE ABRT);",
        "Die on INT or QUIT:",
        "use sigtrap qw(die INT QUIT);",
        "Die on HUP, INT, PIPE or TERM:",
        "use sigtrap qw(die normal-signals);",
        "Die on HUP, INT, PIPE or TERM, except don't change the behavior for signals which are already",
        "trapped or ignored:",
        "use sigtrap qw(die untrapped normal-signals);",
        "Die on receipt one of an of the normal-signals which is currently untrapped, provide a stack",
        "trace on receipt of any of the error-signals:",
        "use sigtrap qw(die untrapped normal-signals",
        "stack-trace any error-signals);",
        "Install myhandler() as the handler for the normal-signals:",
        "use sigtrap 'handler', \\&myhandler, 'normal-signals';",
        "Install myhandler() as the handler for the normal-signals, provide a Perl stack trace on",
        "receipt of one of the error-signals:",
        "use sigtrap qw(handler myhandler normal-signals",
        "stack-trace error-signals);"
    ],
    "see_also": []
}