Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
How to know what the 'errno' means in Linux?
Errno is a global variable in Linux and Unix systems that indicates the type of error that occurred during system calls and library function execution. When a system call or library function encounters an error, it sets the errno variable to a specific integer value that corresponds to the type of error. This mechanism allows developers to identify and handle different types of errors programmatically.
The errno variable is defined in the <errno.h> header file and is thread-local in modern implementations. Each error code has both a numeric value and a symbolic constant name written in uppercase letters.
Common Errno Values
Here are some frequently encountered errno symbols −
EPERM - Operation not permitted ENOENT - No such file or directory ESRCH - No such process EINTR - Interrupted system call EIO - Input/output error ENXIO - No such device or address
Installing the Errno Tool
While errno values are built into the system, you can install a command-line tool to easily look up error meanings −
For Ubuntu/Debian
sudo apt-get install errno
For CentOS/RHEL
yum install errno
Using the Errno Tool
Once installed, you can list all errno symbols and their descriptions −
errno -l
1 EPERM Operation not permitted 2 ENOENT No such file or directory 3 ESRCH No such process 4 EINTR Interrupted system call 5 EIO Input/output error 6 ENXIO No such device or address 7 E2BIG Argument list too long 8 ENOEXEC Exec format error 9 EBADF Bad file descriptor 10 ECHILD No child processes
The complete list contains over 130 different errno values. You can also query a specific errno number −
errno 2
ENOENT 2 No such file or directory
Alternative Methods
If the errno tool is not available, you can use other methods to interpret error codes −
perror "Error message"
Or check the system's error code documentation −
man 3 errno
Practical Usage
In C programs, you typically check errno after a system call fails −
#include <errno.h>
#include <stdio.h>
#include <string.h>
if (some_system_call() == -1) {
printf("Error: %s
", strerror(errno));
}
Conclusion
Understanding errno values is essential for debugging Linux system errors and developing robust applications. The errno tool provides a convenient way to look up error meanings, while the underlying mechanism helps developers identify and handle specific error conditions in their code.
