Errors: Linux System Errors

本文详细列举了Linux系统中各种错误代码及其含义,包括常见的文件操作错误、内存错误、设备错误等,对于理解Linux系统调用失败时返回的错误码非常有帮助。

http://www-numi.fnal.gov/computing/minossoft/releases/R2.3/WebDocs/Errors/unix_system_errors.html

Errors: Linux System Errors

When system requests fail, error code are returned. To understand the nature of the error these codes need to be interpreted. They are recorded in:-
  /usr/include/asm/errno.h
Here is a copy of that file as of Aug 2004 on RedHat 7.3
#define EPERM            1      /* Operation not permitted */
#define ENOENT           2      /* No such file or directory */
#define ESRCH            3      /* No such process */
#define EINTR            4      /* Interrupted system call */
#define EIO              5      /* I/O error */
#define ENXIO            6      /* No such device or address */
#define E2BIG            7      /* Arg list too long */
#define ENOEXEC          8      /* Exec format error */
#define EBADF            9      /* Bad file number */
#define ECHILD          10      /* No child processes */
#define EAGAIN          11      /* Try again */
#define ENOMEM          12      /* Out of memory */
#define EACCES          13      /* Permission denied */
#define EFAULT          14      /* Bad address */
#define ENOTBLK         15      /* Block device required */
#define EBUSY           16      /* Device or resource busy */
#define EEXIST          17      /* File exists */
#define EXDEV           18      /* Cross-device link */
#define ENODEV          19      /* No such device */
#define ENOTDIR         20      /* Not a directory */
#define EISDIR          21      /* Is a directory */
#define EINVAL          22      /* Invalid argument */
#define ENFILE          23      /* File table overflow */
#define EMFILE          24      /* Too many open files */
#define ENOTTY          25      /* Not a typewriter */
#define ETXTBSY         26      /* Text file busy */
#define EFBIG           27      /* File too large */
#define ENOSPC          28      /* No space left on device */
#define ESPIPE          29      /* Illegal seek */
#define EROFS           30      /* Read-only file system */
#define EMLINK          31      /* Too many links */
#define EPIPE           32      /* Broken pipe */
#define EDOM            33      /* Math argument out of domain of func */
#define ERANGE          34      /* Math result not representable */
#define EDEADLK         35      /* Resource deadlock would occur */
#define ENAMETOOLONG    36      /* File name too long */
#define ENOLCK          37      /* No record locks available */
#define ENOSYS          38      /* Function not implemented */
#define ENOTEMPTY       39      /* Directory not empty */
#define ELOOP           40      /* Too many symbolic links encountered */
#define EWOULDBLOCK     EAGAIN  /* Operation would block */
#define ENOMSG          42      /* No message of desired type */
#define EIDRM           43      /* Identifier removed */
#define ECHRNG          44      /* Channel number out of range */
#define EL2NSYNC        45      /* Level 2 not synchronized */
#define EL3HLT          46      /* Level 3 halted */
#define EL3RST          47      /* Level 3 reset */
#define ELNRNG          48      /* Link number out of range */
#define EUNATCH         49      /* Protocol driver not attached */
#define ENOCSI          50      /* No CSI structure available */
#define EL2HLT          51      /* Level 2 halted */
#define EBADE           52      /* Invalid exchange */
#define EBADR           53      /* Invalid request descriptor */
#define EXFULL          54      /* Exchange full */
#define ENOANO          55      /* No anode */
#define EBADRQC         56      /* Invalid request code */
#define EBADSLT         57      /* Invalid slot */

#define EDEADLOCK       EDEADLK

#define EBFONT          59      /* Bad font file format */
#define ENOSTR          60      /* Device not a stream */
#define ENODATA         61      /* No data available */
#define ETIME           62      /* Timer expired */
#define ENOSR           63      /* Out of streams resources */
#define ENONET          64      /* Machine is not on the network */
#define ENOPKG          65      /* Package not installed */
#define EREMOTE         66      /* Object is remote */
#define ENOLINK         67      /* Link has been severed */
#define EADV            68      /* Advertise error */
#define ESRMNT          69      /* Srmount error */
#define ECOMM           70      /* Communication error on send */
#define EPROTO          71      /* Protocol error */
#define EMULTIHOP       72      /* Multihop attempted */
#define EDOTDOT         73      /* RFS specific error */
#define EBADMSG         74      /* Not a data message */
#define EOVERFLOW       75      /* Value too large for defined data type */
#define ENOTUNIQ        76      /* Name not unique on network */
#define EBADFD          77      /* File descriptor in bad state */
#define EREMCHG         78      /* Remote address changed */
#define ELIBACC         79      /* Can not access a needed shared library */
#define ELIBBAD         80      /* Accessing a corrupted shared library */
#define ELIBSCN         81      /* .lib section in a.out corrupted */
#define ELIBMAX         82      /* Attempting to link in too many shared libraries */
#define ELIBEXEC        83      /* Cannot exec a shared library directly */
#define EILSEQ          84      /* Illegal byte sequence */
#define ERESTART        85      /* Interrupted system call should be restarted */
#define ESTRPIPE        86      /* Streams pipe error */
#define EUSERS          87      /* Too many users */
#define ENOTSOCK        88      /* Socket operation on non-socket */
#define EDESTADDRREQ    89      /* Destination address required */
#define EMSGSIZE        90      /* Message too long */
#define EPROTOTYPE      91      /* Protocol wrong type for socket */
#define ENOPROTOOPT     92      /* Protocol not available */
#define EPROTONOSUPPORT 93      /* Protocol not supported */
#define ESOCKTNOSUPPORT 94      /* Socket type not supported */
#define EOPNOTSUPP      95      /* Operation not supported on transport endpoint */
#define EPFNOSUPPORT    96      /* Protocol family not supported */
#define EAFNOSUPPORT    97      /* Address family not supported by protocol */
#define EADDRINUSE      98      /* Address already in use */
#define EADDRNOTAVAIL   99      /* Cannot assign requested address */
#define ENETDOWN        100     /* Network is down */
#define ENETUNREACH     101     /* Network is unreachable */
#define ENETRESET       102     /* Network dropped connection because of reset */
#define ECONNABORTED    103     /* Software caused connection abort */
#define ECONNRESET      104     /* Connection reset by peer */
#define ENOBUFS         105     /* No buffer space available */
#define EISCONN         106     /* Transport endpoint is already connected */
#define ENOTCONN        107     /* Transport endpoint is not connected */
#define ESHUTDOWN       108     /* Cannot send after transport endpoint shutdown */
#define ETOOMANYREFS    109     /* Too many references: cannot splice */
#define ETIMEDOUT       110     /* Connection timed out */
#define ECONNREFUSED    111     /* Connection refused */
#define EHOSTDOWN       112     /* Host is down */
#define EHOSTUNREACH    113     /* No route to host */
#define EALREADY        114     /* Operation already in progress */
#define EINPROGRESS     115     /* Operation now in progress */
#define ESTALE          116     /* Stale NFS file handle */
#define EUCLEAN         117     /* Structure needs cleaning */
#define ENOTNAM         118     /* Not a XENIX named type file */
#define ENAVAIL         119     /* No XENIX semaphores available */
#define EISNAM          120     /* Is a named type file */
#define EREMOTEIO       121     /* Remote I/O error */
#define EDQUOT          122     /* Quota exceeded */

#define ENOMEDIUM       123     /* No medium found */
#define EMEDIUMTYPE     124     /* Wrong medium type */

Go Back to the  The Errors Top Page

URL http://www-numi.fnal.gov/computing/minossoft/releases/R2.3/WebDocs/Errors/unix_system_errors.html
Last modified : 12/31/2012 10:29:31

Contact: Nick West (n.west1@physics.oxford.ac.uk>)
### 3.1 使用命令行工具查看网络接口名称和数量 Linux 系统提供了多种命令行工具用于查看网络接口的名称和数量,其中最常用的是 `ip` 和 `ifconfig` 命令。`ip` 命令是现代 Linux 发行版推荐使用的工具,它能够显示和操作网络接口、路由表、策略路由等信息。使用以下命令可以查看当前系统中的网络接口: ```bash ip link show ``` 该命令会列出所有网络接口,包括物理网卡(如 `eth0`, `eth1`)、无线网卡(如 `wlan0`)、回环接口(`lo`)等,并显示它们的状态(UP/DOWN)[^2]。 如果系统中安装了 `ifconfig` 工具,也可以使用以下命令查看网络接口信息: ```bash ifconfig -a ``` 该命令会显示所有网络接口的详细信息,包括接口名称、IP 地址、子网掩码、广播地址等。需要注意的是,`ifconfig` 在某些现代 Linux 发行版中已被弃用,推荐使用 `ip` 命令替代[^1]。 ### 3.2 查看网络接口配置文件 除了使用命令行工具外,还可以通过查看网络接口的配置文件来获取接口名称和配置信息。在大多数 Linux 系统中,网络接口的配置文件通常位于 `/etc/sysconfig/network-scripts/` 目录下(如 CentOS、RHEL 等系统),文件名格式为 `ifcfg-<interface_name>`,例如 `ifcfg-eth0`。以下是一个典型的网络接口配置文件示例: ```bash # This file describes the network interfaces available on your system # and how to activate them. For more information, see interfaces(5). # The loopback network interface auto lo iface lo inet loopback # The primary network interface auto eth0 iface eth0 inet static address 192.168.1.254 network 192.168.1.0 netmask 255.255.255.0 broadcast 192.168.1.255 gateway 192.168.1.1 auto eth1 iface eth1 inet dhcp ``` 该配置文件定义了两个网络接口 `eth0` 和 `eth1`,其中 `eth0` 配置为静态 IP 地址,`eth1` 则通过 DHCP 动态获取 IP 地址[^3]。 ### 3.3 使用 ethtool 确认物理接口状态 在编写 C 语言代码时,若需要指定特定的网络接口(如 `eth0`),除了查看接口名称外,还可以使用 `ethtool` 命令确认物理接口是否连接网线。例如: ```bash ethtool eth0 ``` 该命令会显示 `eth0` 接口的详细信息,包括是否检测到链路连接(Link detected: yes/no)。如果发现某个接口未连接网线,可以尝试使用以下命令启用接口: ```bash ifconfig eth0 up ``` 如果 `ifconfig` 不可用,可以使用 `ip` 命令替代: ```bash ip link set eth0 up ``` 此外,还可以使用 `ethtool -p` 命令使指定接口的物理指示灯闪烁,从而帮助识别服务器上的物理网口: ```bash ethtool -p eth0 30 ``` 该命令会使 `eth0` 接口的指示灯闪烁 30 秒,便于确认网线插入的物理位置[^4]。 ### 3.4 网络接口在 C 语言程序中的使用 在 C 语言程序中使用特定网络接口时,通常需要通过 socket 编程绑定到指定接口。例如,使用 `setsockopt` 设置 `SO_BINDTODEVICE` 选项可以将 socket 绑定到特定的网络接口: ```c #include <sys/socket.h> #include <netinet/in.h> #include <string.h> #include <stdio.h> #include <unistd.h> int main() { int sockfd = socket(AF_INET, SOCK_DGRAM, 0); if (sockfd < 0) { perror("socket"); return 1; } const char *interface = "eth0"; if (setsockopt(sockfd, SOL_SOCKET, SO_BINDTODEVICE, interface, strlen(interface) + 1) < 0) { perror("setsockopt"); close(sockfd); return 1; } // 继续进行网络通信操作... close(sockfd); return 0; } ``` 上述代码创建了一个 UDP socket,并将其绑定到 `eth0` 接口,确保数据通过该接口发送[^1]。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值