Error Numbers Linux
Contents |
In C programming language, there is no direct support for error handling. You have to detect the failure and handle the error. In C programming language, return values represents success or failure. Inside a C program, when a eagain error linux function fails, you should handle the errors accordingly, or at least record the errors in a linux error codes log file. When you are running some program on Linux environment, you might notice that it gives some error number. For example, "Error linux errno no is : 17", which doesn't really say much. You really need to know what error number 17 means. This article shows all available error numbers along with it descriptions. This article might be a handy reference for you,
Linux Error Codes 127
when you encounter an error number and you would like to know what it means. In C programming language, there is an external variable called "errno". From this errno variable you can use some error handling functions to find out the error description and handle it appropriately. You have to include errno.h header file to use external variable errno. perror function prints error description in standard error. The strerror function returns a string describing the error code linux kernel error codes passed in the argument errnum. The following C code snippet tries to open a file through open system call. There are two flags in the open call. O_CREAT flag is to create a file, if the file does not exist. O_EXCL flag is used with O_CREAT, if the file is already exist open call will fail with the proper error number. $ cat fileopen.c #include
codes can’t occur on GNU systems, but they can occur using the GNU C Library on other systems. Macro: int EPERM Operation not permitted; only linux exit codes the owner of the file (or other resource) or processes with special
Linux Errno Example
privileges can perform the operation. Macro: int ENOENT No such file or directory. This is a “file doesn’t exist”
Posix Error Codes
error for ordinary files that are referenced in contexts where they are expected to already exist. Macro: int ESRCH No process matches the specified process ID. Macro: int EINTR Interrupted function http://www.thegeekstuff.com/2010/10/linux-error-codes call; an asynchronous signal occurred and prevented completion of the call. When this happens, you should try the call again. You can choose to have functions resume after a signal that is handled, rather than failing with EINTR; see Interrupted Primitives. Macro: int EIO Input/output error; usually used for physical read or write errors. Macro: int ENXIO No such device or address. http://www.gnu.org/s/libc/manual/html_node/Error-Codes.html The system tried to use the device represented by a file you specified, and it couldn’t find the device. This can mean that the device file was installed incorrectly, or that the physical device is missing or not correctly attached to the computer. Macro: int E2BIG Argument list too long; used when the arguments passed to a new program being executed with one of the exec functions (see Executing a File) occupy too much memory space. This condition never arises on GNU/Hurd systems. Macro: int ENOEXEC Invalid executable file format. This condition is detected by the exec functions; see Executing a File. Macro: int EBADF Bad file descriptor; for example, I/O on a descriptor that has been closed or reading from a descriptor open only for writing (or vice versa). Macro: int ECHILD There are no child processes. This error happens on operations that are supposed to manipulate child processes, when there aren’t any processes to manipulate. Macro: int EDEADLK Deadlock avoided; allocating a system resource would have resulted in a deadlock situation. The system does not guarantee that it will notice all such situatio
>ExampleComments1Catchall for general errorslet "var1 = 1/0"Miscellaneous errors, such as "divide by zero" and other impermissible operations2http://tldp.org/LDP/abs/html/exitcodes.html >Misuse of shell builtins (according to Bash documentation)empty_function() {}Missing keyword or command, or permission problem (and diff return code on a failed binary file comparison).http://nullprogram.com/blog/2016/09/23/ >126Command invoked cannot execute/dev/nullPermission problem or command is not an executable127"command not found"illegal_commandPossible problem with $PATH or a typo128Invalid argument to exitexit 3.14159exit takes only integer args in the range 0 - 255 (see first footnote)128+nFatal error signal "n"kill -9 $PPID of script$? returns 137 (128 + 9)130Script terminated by Control-CCtl-CControl-C is fatal error linux error codes signal 2, (130 = 128 + 2, see above)255*Exit status out of rangeexit -1exit takes only integer args in the range 0 - 255
questioner was looking to use threads in a program without any libc dependency. However, he was concerned about checking for mmap(2) errors when allocating the thread’s stack. The mmap(2) man page says it returns -1 (a.k.a. MAP_FAILED) on error and sets errno. But how do you check errno without libc? As a reminder here’s what the (unoptimized) assembly looks like. stack_create: mov rdi, 0 mov rsi, STACK_SIZE mov rdx, PROT_WRITE | PROT_READ mov r10, MAP_ANONYMOUS | MAP_PRIVATE | MAP_GROWSDOWN mov rax, SYS_mmap syscall ret As usual, the system call return value is in rax, which becomes the return value for stack_create(). Again, its C prototype would look like this: void *stack_create(void); If you were to, say, intentionally botch the arguments to force an error, you might notice that the system call isn’t returning -1, but other negative values. What gives? The trick is that errno is a C concept. That’s why it’s documented as errno(3)