Oihana PHP Commands

ExitCode uses ConstantsTrait

Standard UNIX exit codes

The exit status of an executed command is the value returned by the waitpid system call or equivalent function.

Exit statuses fall between 0 and 255, though, as explained below, the shell may use values above 125 specially. Exit statuses from shell builtins and compound commands are also limited to this range. Under certain circumstances, the shell will use special values to indicate specific failure modes.

Tags
see
https://tldp.org/LDP/abs/html/exitcodes.html
see
https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
see
https://man7.org/linux/man-pages/man7/signal.7.html
author

Marc Alcaraz (ekameleon)

since
1.0.0

Table of Contents

Constants

CANNOT_EXECUTE  = 126
Command invoked cannot execute.
COMMAND_NOT_FOUND  = 127
Command not found.
EXIT_STATUS_OUT_OF_RANGE  = 255
Exit status out of range.
FAILURE  = 1
Catchall for general errors.
INVALID  = 2
Misuse of shell builtins.
INVALID_ARGUMENT_TO_EXIT  = 128
Invalid argument to exit Exit takes only integer args in the range 0 - 255 (see first footnote)
SIGABRT  = 134
Abort signal from abort(3).
SIGALRM  = 142
Alarm clock (timer signal from alarm(2)).
SIGBUS  = 135
Bus error (bad memory access).
SIGCHLD  = 145
Child stopped or terminated.
SIGCONT  = 146
Continue if stopped.
SIGFPE  = 136
Floating-point exception.
SIGHUP  = 129
Hangup detected on controlling terminal or death of controlling process.
SIGILL  = 132
Illegal instruction.
SIGINT  = 130
Interrupt from keyboard (Control-C).
SIGIO  = 157
I/O now possible.
SIGKILL  = 137
Kill signal (cannot be caught or ignored).
SIGPIPE  = 141
Broken pipe: write to pipe with no readers.
SIGPROF  = 155
Profiling timer expired.
SIGPWR  = 158
Power failure (not all systems).
SIGQUIT  = 131
Quit from keyboard (often Control-\).
SIGSEGV  = 139
Invalid memory reference (segmentation fault).
SIGSTKFLT  = 144
Stack fault on coprocessor (unused on most systems).
SIGSTOP  = 147
Stop process (cannot be caught or ignored).
SIGSYS  = 159
Bad system call (sometimes SIGSYS).
SIGTERM  = 143
Termination signal.
SIGTRAP  = 133
Trace/breakpoint trap.
SIGTSTP  = 148
Stop typed at terminal.
SIGTTIN  = 149
Terminal input for background process.
SIGTTOU  = 150
Terminal output for background process.
SIGURG  = 151
Urgent condition on socket.
SIGUSR1  = 138
User-defined signal 1.
SIGUSR2  = 140
User-defined signal 2.
SIGVTALRM  = 154
Virtual alarm clock.
SIGWINCH  = 156
Window resize signal.
SIGXCPU  = 152
CPU time limit exceeded.
SIGXFSZ  = 153
File size limit exceeded.
SUCCESS  = 0
Command succeed.
TERMINATED_BY_SIGNAL  = 128
Fatal error signal "n".

Properties

$signalMap  : array<string|int, mixed>
Signal code-to-name mapping.

Methods

getCodeForSignal()  : int|null
Returns the exit code for a given signal name.
getSignalName()  : string|null
Returns the signal name for a given exit code if applicable.

Constants

CANNOT_EXECUTE

Command invoked cannot execute.

public mixed CANNOT_EXECUTE = 126

Permission problem or command is not an executable.

COMMAND_NOT_FOUND

Command not found.

public mixed COMMAND_NOT_FOUND = 127

Possible problem with $PATH or a typo

EXIT_STATUS_OUT_OF_RANGE

Exit status out of range.

public mixed EXIT_STATUS_OUT_OF_RANGE = 255

Exit status codes above 255 are usually truncated modulo 256.

FAILURE

Catchall for general errors.

public mixed FAILURE = 1

Miscellaneous errors, such as "divide by zero" and other impermissible operations

INVALID

Misuse of shell builtins.

public mixed INVALID = 2

Missing keyword or command, or permission problem (and diff return code on a failed binary file comparison).

INVALID_ARGUMENT_TO_EXIT

Invalid argument to exit Exit takes only integer args in the range 0 - 255 (see first footnote)

public mixed INVALID_ARGUMENT_TO_EXIT = 128

SIGABRT

Abort signal from abort(3).

public mixed SIGABRT = 134

SIGALRM

Alarm clock (timer signal from alarm(2)).

public mixed SIGALRM = 142

SIGBUS

Bus error (bad memory access).

public mixed SIGBUS = 135

SIGCHLD

Child stopped or terminated.

public mixed SIGCHLD = 145

SIGCONT

Continue if stopped.

public mixed SIGCONT = 146

SIGFPE

Floating-point exception.

public mixed SIGFPE = 136

SIGHUP

Hangup detected on controlling terminal or death of controlling process.

public mixed SIGHUP = 129

SIGILL

Illegal instruction.

public mixed SIGILL = 132

SIGINT

Interrupt from keyboard (Control-C).

public mixed SIGINT = 130

SIGIO

I/O now possible.

public mixed SIGIO = 157

SIGKILL

Kill signal (cannot be caught or ignored).

public mixed SIGKILL = 137

SIGPIPE

Broken pipe: write to pipe with no readers.

public mixed SIGPIPE = 141

SIGPROF

Profiling timer expired.

public mixed SIGPROF = 155

SIGPWR

Power failure (not all systems).

public mixed SIGPWR = 158

SIGQUIT

Quit from keyboard (often Control-\).

public mixed SIGQUIT = 131

SIGSEGV

Invalid memory reference (segmentation fault).

public mixed SIGSEGV = 139

SIGSTKFLT

Stack fault on coprocessor (unused on most systems).

public mixed SIGSTKFLT = 144

SIGSTOP

Stop process (cannot be caught or ignored).

public mixed SIGSTOP = 147

SIGSYS

Bad system call (sometimes SIGSYS).

public mixed SIGSYS = 159

SIGTERM

Termination signal.

public mixed SIGTERM = 143

SIGTRAP

Trace/breakpoint trap.

public mixed SIGTRAP = 133

SIGTSTP

Stop typed at terminal.

public mixed SIGTSTP = 148

SIGTTIN

Terminal input for background process.

public mixed SIGTTIN = 149

SIGTTOU

Terminal output for background process.

public mixed SIGTTOU = 150

SIGURG

Urgent condition on socket.

public mixed SIGURG = 151

SIGUSR1

User-defined signal 1.

public mixed SIGUSR1 = 138

SIGUSR2

User-defined signal 2.

public mixed SIGUSR2 = 140

SIGVTALRM

Virtual alarm clock.

public mixed SIGVTALRM = 154

SIGWINCH

Window resize signal.

public mixed SIGWINCH = 156

SIGXCPU

CPU time limit exceeded.

public mixed SIGXCPU = 152

SIGXFSZ

File size limit exceeded.

public mixed SIGXFSZ = 153

SUCCESS

Command succeed.

public mixed SUCCESS = 0

TERMINATED_BY_SIGNAL

Fatal error signal "n".

public mixed TERMINATED_BY_SIGNAL = 128

Signal numbers start at 1; 128 + n indicates termination by signal. For example, 130 = script terminated by Control-C (SIGINT).

Properties

$signalMap

Signal code-to-name mapping.

private static array<string|int, mixed> $signalMap = [self::SIGHUP => 'SIGHUP', self::SIGINT => 'SIGINT', self::SIGQUIT => 'SIGQUIT', self::SIGILL => 'SIGILL', self::SIGTRAP => 'SIGTRAP', self::SIGABRT => 'SIGABRT', self::SIGBUS => 'SIGBUS', self::SIGFPE => 'SIGFPE', self::SIGKILL => 'SIGKILL', self::SIGUSR1 => 'SIGUSR1', self::SIGSEGV => 'SIGSEGV', self::SIGUSR2 => 'SIGUSR2', self::SIGPIPE => 'SIGPIPE', self::SIGALRM => 'SIGALRM', self::SIGTERM => 'SIGTERM', self::SIGSTKFLT => 'SIGSTKFLT', self::SIGCHLD => 'SIGCHLD', self::SIGCONT => 'SIGCONT', self::SIGSTOP => 'SIGSTOP', self::SIGTSTP => 'SIGTSTP', self::SIGTTIN => 'SIGTTIN', self::SIGTTOU => 'SIGTTOU', self::SIGURG => 'SIGURG', self::SIGXCPU => 'SIGXCPU', self::SIGXFSZ => 'SIGXFSZ', self::SIGVTALRM => 'SIGVTALRM', self::SIGPROF => 'SIGPROF', self::SIGWINCH => 'SIGWINCH', self::SIGIO => 'SIGIO', self::SIGPWR => 'SIGPWR', self::SIGSYS => 'SIGSYS']

Methods

getCodeForSignal()

Returns the exit code for a given signal name.

public static getCodeForSignal(string $signalName) : int|null
Parameters
$signalName : string

Signal name (case-insensitive, e.g. "sigterm").

Tags
example
echo ExitCode::getCodeForSignal(' sigterm' ) ; // 143
Return values
int|null

Exit code (e.g. 143) or null if not found.

getSignalName()

Returns the signal name for a given exit code if applicable.

public static getSignalName(int $code) : string|null
Parameters
$code : int

Exit code to check.

Tags
example
echo ExitCode::getSignalName( 137 ) ; // SIGKILL

var_dump( ExitCode::getSignalName( 0 ) ) ; // null

$code   = 137;
$signal = ExitCode::getSignalName( $code ) ;
if ( $signal )
{
    echo "Process terminated by signal: {$signal}";
}
else
{
    echo "Exit code: {$code}";
}
Return values
string|null

The signal name (e.g. "SIGKILL") or null if not a signal.


        
On this page

Search results