Sysexit h

Re: how are sysexit.h statues interpreted

#ifndef _SYSEXITS_H #define _SYSEXITS_H #define EX_OK 0 #define EX__​BASE 64 #define EX_USAGE 64 #define EX_DATAERR 65 #define. DESCRIPTION. No really, just a thin wrapper around sysexits(3) for those constants. See POSIX for the EXIT_FAILURE and EXIT_SUCCESS stdlib constants. SYSEXITS(3) FreeBSD Library Functions Manual SYSEXITS(3) NAME sysexits - preferable exit codes for programs SYNOPSIS #include.

#include #include #include #include . In sysexits.h, mentioned in the most popular answer, exit status. #ifndef _SYSEXITS_H #define _SYSEXITS_H #define EX_OK 0 #define EX__​BASE 64 #define EX_USAGE 64 #define EX_DATAERR 65 #define. Mail -> IO ExitCodeSource. inventMessageId:: IO HeaderSource. exitcodeToSYSEXIT:: ExitCode -> SYSEXITSource. data SYSEXIT Source. from sysexit.h.

DESCRIPTION. No really, just a thin wrapper around sysexits(3) for those constants. See POSIX for the EXIT_FAILURE and EXIT_SUCCESS stdlib constants. SYSEXITS(3) FreeBSD Library Functions Manual SYSEXITS(3) NAME sysexits - preferable exit codes for programs SYNOPSIS #include. #ifndef _SYSEXITS_H #define _SYSEXITS_H #define EX_OK 0 #define EX__​BASE 64 #define EX_USAGE 64 #define EX_DATAERR 65 #define.






This module provides access to some variables used or maintained by the interpreter and to functions that interact strongly with the interpreter. It is always available. The list of command line arguments passed to a Python script.

If the command was executed using the -c command line option to the interpreter, argv[0] is set to the string '-c'. If no script name was sysexit to the Python interpreter, argv[0] is the empty string.

To loop over the standard input, or the list of files given on the command line, see the fileinput module. An indicator of the native byte order.

This will have the value 'big' on big-endian most-significant byte first platforms, and 'little' on little-endian least-significant byte first platforms. A tuple of strings sysexit sysecit names of all modules that are compiled into this Python interpreter. This information is not available in any other way — modules. The tracing state is saved, and restored afterwards.

This is intended to be called from a debugger from a checkpoint, to recursively debug some other code. Clear the internal type cache. The type cache is used to speed up attribute sysexkt method lookups. Use the function only to drop unnecessary references during reference leak debugging. Note that xysexit in the traceback module can build the call stack given such a frame. If value is not Nonethis function prints it to sys. The display of these values can be customized syssxit assigning another one-argument function to sys.

This function prints out a given traceback and exception to sys. When an exception is raised and sysexit, the interpreter calls sys. In an interactive session this happens just before control is returned sysexitt the prompt; in a Python program this happens just before the program exits.

The handling of such top-level exceptions can be customized by assigning another three-argument function to sys. These objects contain the original values of displayhook and excepthook at the start of the program. They are saved so that displayhook and excepthook can be restored in case they happen to get replaced with broken objects. This function returns a sysfxit of three values that give information about the exception that is currently being handled.

The information returned is specific both to the current thread and to the current stack frame. If the current stack frame is not handling an susexit, the information is taken from the calling stack frame, or its caller, and so sysexit until a stack frame is found sjsexit is handling an exception.

If no exception is being handled anywhere on the stack, a tuple containing three None values is returned. Otherwise, the values returned are type, value, traceback. Their meaning is: type gets the exception type of the exception being handled susexit class object ; value gets the exception parameter its associated value or the second argument to raisewhich is always a class instance if the exception type is a class object ; traceback gets a traceback object see the Reference Manual which encapsulates the ssyexit stack at the point where the exception originally occurred.

Assigning the traceback return value to a local variable in a function that is handling an exception will cause a circular reference. This will prevent anything referenced by a local variable in the same function or by the traceback from being garbage collected.

Beginning with Python 2. This function clears all information relating to the current or last exception that occurred in the current thread. This function is only needed in only a few obscure situations. These include logging and error handling systems that report sysexit on the last or current exception. This function can also be used to try to free resources and trigger object finalization, though no guarantee is made as to what objects will be freed, if sywexit.

Deprecated since version 1. Since they are global variables, they are not specific to the current thread, so their use is not safe sgsexit a multi-threaded program. This can be set at build time with the --exec-prefix argument to the configure script. Specifically, all configuration files e. Y is the version number of Python, for example sysexit.

A string giving the absolute path of the executable binary for the Python interpreter, on systems where this makes sense. If Python is unable to retrieve the real path to its executable, sys. Exit from Python. This is implemented by raising the SystemExit exception, so cleanup actions specified by finally clauses of try statements are honored, and it is possible to intercept the exit attempt at an outer level. The optional argument arg can be an integer giving the exit status defaulting to zeroor another type of object.

Most systems require it to be in the range 0—, y produce undefined results otherwise. Some systems have a convention for assigning specific meanings to specific exit codes, but these are generally underdeveloped; Unix programs generally use 2 for command sysexig syntax errors and 1 for all other kind of errors.

If another type of object is passed, None is equivalent to passing zero, and any other object is printed to stderr and results in an exit code of 1. In particular, sys. This value is not actually defined by the sysexut, but can be set ssysexit the user or by a program to specify a clean-up action at program exit. When set, it should be a parameterless function. This function will be called when the interpreter exits.

Only one function may be installed in this way; to allow multiple n which will be called at termination, use the atexit module. The exit function is not called when the program is sysexit by a signal, when a Python fatal internal error is detected, or when os. Deprecated since version 2. The struct sequence flags exposes the status of command sysexit flags. The attributes sysexut read only. New in version 2. A structseq holding information about the float type. It contains low level information about the precision and internal representation.

The values correspond to the various floating-point constants defined in the standard header file float. See section 5. The attribute sys. If s is any string representing a decimal number with at most sys.

But for strings with more than sys. A string indicating how the repr function behaves for floats. This is the usual behaviour in Python 2. Return the current value of the flags that are used sysexitt dlopen calls.

Availability: Unix. Return the name of the encoding used to convert Unicode filenames into system file names, or None if the system default encoding is used.

The result value depends on the operating system:. On Mac OS X, the encoding is 'utf-8'. On Windows 9x, the encoding is 'mbcs'. Return the sysxeit count of the object. The count returned is generally one higher than you might expect, because it includes the temporary reference as an argument to getrefcount. Return the current value of the syzexit limit, the maximum depth of the Python interpreter stack. This limit prevents infinite recursion from causing an overflow sysecit the C stack and crashing Python.

It can be set by setrecursionlimit. Return the size of an object in bytes. The object can be any type of object. All built-in objects will return sysexit results, but this does not have to hold true for third-party extensions as it is implementation specific. If given, default will be returned if the object does not provide means to retrieve the size. Otherwise a TypeError will be raised. Return a frame object from the call stack.

If optional integer depth is given, return the frame object that many calls below the top of the stack. If that is deeper than the call stack, ValueError is raised. The default for depth is zero, returning susexit frame at the top of the call stack. CPython implementation detail: This function should be used sysexot internal and specialized purposes only.

It is not guaranteed to exist in all implementations of Python. Get sysexit profiler function as set by setprofile. Eysexit the trace function as set by xysexit. CPython wysexit detail: The gettrace function is intended only for implementing debuggers, profilers, coverage tools and the like. Its behavior is part of the implementation platform, rather than part of the language definition, and thus may not be available in all Python implementations. Return a named tuple describing the Windows version currently running.

The components can also be accessed by name, so sys. For compatibility with prior versions, only the first 5 sysdxit are retrievable by indexing.

Changed in version 2.

Beginning with Python 2. This function clears all information relating to the current or last exception that occurred in the current thread. This function is only needed in only a few obscure situations. These include logging and error handling systems that report information on the last or current exception.

This function can also be used to try to free resources and trigger object finalization, though no guarantee is made as to what objects will be freed, if any. Deprecated since version 1.

Since they are global variables, they are not specific to the current thread, so their use is not safe in a multi-threaded program. This can be set at build time with the --exec-prefix argument to the configure script.

Specifically, all configuration files e. Y is the version number of Python, for example 2. A string giving the absolute path of the executable binary for the Python interpreter, on systems where this makes sense.

If Python is unable to retrieve the real path to its executable, sys. Exit from Python. This is implemented by raising the SystemExit exception, so cleanup actions specified by finally clauses of try statements are honored, and it is possible to intercept the exit attempt at an outer level.

The optional argument arg can be an integer giving the exit status defaulting to zero , or another type of object. Most systems require it to be in the range 0—, and produce undefined results otherwise. Some systems have a convention for assigning specific meanings to specific exit codes, but these are generally underdeveloped; Unix programs generally use 2 for command line syntax errors and 1 for all other kind of errors. If another type of object is passed, None is equivalent to passing zero, and any other object is printed to stderr and results in an exit code of 1.

In particular, sys. This value is not actually defined by the module, but can be set by the user or by a program to specify a clean-up action at program exit. When set, it should be a parameterless function.

This function will be called when the interpreter exits. Only one function may be installed in this way; to allow multiple functions which will be called at termination, use the atexit module.

The exit function is not called when the program is killed by a signal, when a Python fatal internal error is detected, or when os. Deprecated since version 2. The struct sequence flags exposes the status of command line flags.

The attributes are read only. New in version 2. A structseq holding information about the float type. It contains low level information about the precision and internal representation. The values correspond to the various floating-point constants defined in the standard header file float. See section 5. The attribute sys. If s is any string representing a decimal number with at most sys. But for strings with more than sys.

A string indicating how the repr function behaves for floats. This is the usual behaviour in Python 2. Return the current value of the flags that are used for dlopen calls. Availability: Unix.

Return the name of the encoding used to convert Unicode filenames into system file names, or None if the system default encoding is used. The result value depends on the operating system:. On Mac OS X, the encoding is 'utf-8'. On Windows 9x, the encoding is 'mbcs'. Return the reference count of the object. The count returned is generally one higher than you might expect, because it includes the temporary reference as an argument to getrefcount.

Return the current value of the recursion limit, the maximum depth of the Python interpreter stack. This limit prevents infinite recursion from causing an overflow of the C stack and crashing Python. It can be set by setrecursionlimit. Return the size of an object in bytes. The object can be any type of object. All built-in objects will return correct results, but this does not have to hold true for third-party extensions as it is implementation specific.

If given, default will be returned if the object does not provide means to retrieve the size. Otherwise a TypeError will be raised. Return a frame object from the call stack. If optional integer depth is given, return the frame object that many calls below the top of the stack. If that is deeper than the call stack, ValueError is raised. The default for depth is zero, returning the frame at the top of the call stack.

CPython implementation detail: This function should be used for internal and specialized purposes only. It is not guaranteed to exist in all implementations of Python. Get the profiler function as set by setprofile. Get the trace function as set by settrace. CPython implementation detail: The gettrace function is intended only for implementing debuggers, profilers, coverage tools and the like.

Its behavior is part of the implementation platform, rather than part of the language definition, and thus may not be available in all Python implementations. Return a named tuple describing the Windows version currently running. The components can also be accessed by name, so sys. For compatibility with prior versions, only the first 5 elements are retrievable by indexing.

Changed in version 2. The version number encoded as a single integer. This is guaranteed to increase with each version, including proper support for non-production releases. For example, to test that the Python interpreter is at least version 1. This is called hexversion since it only really looks meaningful when viewed as the result of passing it to the built-in hex function. The hexversion is a bit number with the following layout:. Thus 2. These three variables are not always defined; they are set when an exception is not handled and the interpreter prints an error message and a stack traceback.

Their intended use is to allow an interactive user to import a debugger module and engage in post-mortem debugging without having to re-execute the command that caused the error.

Typical use is import pdb; pdb. An integer giving the largest supported code point for a Unicode character. The method returns None if the module cannot be found, else returns a loader. See PEP for the original specification. This is a dictionary that maps module names to modules which have already been loaded. This can be manipulated to force reloading of modules and other tricks. Note that removing a module from this dictionary is not the same as calling reload on the corresponding module object.

A list of strings that specifies the search path for modules. As initialized upon program startup, the first item of this list, path[0] , is the directory containing the script that was used to invoke the Python interpreter. If the script directory is not available e. Module site This describes how to use. A list of callables that take a path argument to try to create a finder for the path.

If a finder can be created, it is to be returned by the callable, else raise ImportError. Originally specified in PEP A dictionary acting as a cache for finder objects.

The keys are paths that have been passed to sys. If a path is a valid file system path but no explicit finder is found on sys. If the path is not an existing path then imp. NullImporter is set.

This string contains a platform identifier that can be used to append platform-specific components to sys. For most Unix systems, this is the lowercased OS name as returned by uname -s with the first part of the version as returned by uname -r appended, e. Unless you want to test for a specific system version, it is therefore recommended to use the following idiom:.

In Python 3. This can be set at build time with the --prefix argument to the configure script. Y while the platform independent header files all except pyconfig. Y , where X. Strings specifying the primary and secondary prompt of the interpreter. These are only defined if the interpreter is in interactive mode. If a non-string object is assigned to either variable, its str is re-evaluated each time the interpreter prepares to read a new interactive command; this can be used to implement a dynamic prompt.

Bool containing the status of the Python 3 warning flag. This integer value determines how often the interpreter checks for periodic things such as thread switches and signal handlers. The default is , meaning the check is performed every Python virtual instructions. But this does not reflect reality: I am not aware of any common Unix utility that returns 64 on incorrect invocation examples welcome.

Careful reading of the source code reveals that sysexits. In other words, these definitions do not reflect the common practice at the time but were intentionally incompatible with it. More's the pity. There are no standard exit codes, aside from 0 meaning success. Non-zero doesn't necessarily mean failure either.

The 11 on segfault is interesting, as 11 is the signal number that the kernel uses to kill the process in the event of a segfault. There is likely some mechanism, either in the kernel or in the shell, that translates that into the exit code. It seems to date back to at least and some big projects like Postfix use it, so I imagine it's the way to go.

To a first approximation, 0 is sucess, non-zero is failure, with 1 being general failure, and anything larger than one being a specific failure. Aside from the trivial exceptions of false and test, which are both designed to give 1 for sucess, there's a few other exceptions I found.

More realistically, 0 means sucess or maybe failure, 1 means general failure or maybe sucess, 2 means general failure if 1 and 0 are both used for sucess, but maybe sucess as well. The diff command gives 0 if files compared are identical, 1 if they differ, and 2 if binaries are different.

The less command gives 1 for failure unless you fail to supply an argument, in which case, it exits 0 despite failing. The more command and the spell command give 1 for failure, unless the failure is a result of permission denied, nonexistent file, or attempt to read a directory.

In any of these cases, they exit 0 despite failing. Then the expr command gives 1 for sucess unless the output is the empty string or zero, in which case, 0 is sucess. Then there's cases where success or failure is ambiguous. When grep fails to find a pattern, it exits 1, but it exits 2 for a genuine failure like permission denied. Klist also exits 1 when it fails to find a ticket, although this isn't really any more of a failure than when grep doesn't find a pattern, or when you ls an empty directory.

So, unfortunately, the unix powers that be don't seem to enforce any logical set of rules, even on very commonly used executables. Programs return a 16 bit exit code. If the program was killed with a signal then the high order byte contains the signal used, otherwise the low order byte is the exit status returned by the programmer.

The only "standard" convention for programs is 0 for success, non-zero for error. Another convention used is to return errno on error. Standard Unix exit codes are defined by sysexits. The same exit codes are used by portable libraries such as Poco - here is a list of them:. This signal is generated by the kernel in response to a bad page access, which causes the program to terminate. A list of signals can be found in the signal man page run "man signal". When Linux returns 0, it means success.

Anything else means failure, each program has its own exit codes, so it would been quite long to list them all About the 11 error code, it's indeed the segmentation fault number, mostly meaning that the program accessed a memory location that was not assigned. Learn more. Are there any standard exit status codes in Linux?

Ask Question. Asked 10 years, 4 months ago. Active 1 year, 3 months ago. Viewed k times. A process is considered to have completed correctly in Linux if its exit status was 0. Are there standard exit codes for processes in Linux? Nathan Fellman Nathan Fellman 96k 83 83 gold badges silver badges bronze badges.

Betlista 8, 8 8 gold badges 53 53 silver badges 88 88 bronze badges. Given the way the question now appears, this does not appear to be the most useful and thus accepted answer. Dec 9 '13 at All rights reserved.

A whole bunch of text left out. IQAndreas 5, 3 3 gold badges 26 26 silver badges 54 54 bronze badges. Schof Schof 5, 5 5 gold badges 24 24 silver badges 34 34 bronze badges. Note that in some flavors of unix, some commands use an exit status of 2 to indicate other things. For instance, many implementations of grep use an exit status of 2 to indicate an error, and use an exit status of 1 to mean that no selected lines were found.

On BSDs there's a man page summarising the info from sysexits. What NamshubWriter said. Exit status 2 is the universal go-to for incorrect command line usage in Unix utilities, not just in "some flavors of unix" but in general.

The header shown in this answer does not reflect actual conventions, now or when it was written in The ABS is not "great". Please read up on the subject; it's not exactly hard to find criticisms. However, for other applications, there are different exit codes.