最近在做工程的时候,程序在崩溃时候弹出了错误号,然后根据错误号搜索错误信息,很快解决之,特此记录。
在程序出错时,我们通过全局变量错误号errno和perror函数能够很快的定位到错误原因。
linux错误代码及其含义
c name | value | description | 含义 |
---|---|---|---|
success | 0 | success | 成功 |
eperm | 1 | operation not permitted | 操作不允许 |
enoent | 2 | no such file or directory | 没有这样的文件或目录 |
esrch | 3 | no such process | 没有这样的过程 |
eintr | 4 | interrupted system call | 系统调用被中断 |
eio | 5 | i/o error | i/o错误 |
enxio | 6 | no such device or address | 没有这样的设备或地址 |
e2big | 7 | arg list too long | 参数列表太长 |
enoexec | 8 | exec format error | 执行格式错误 |
ebadf | 9 | bad file number | 坏的文件描述符 |
echild | 10 | no child processes | 没有子进程 |
eagain | 11 | try again | 资源暂时不可用 |
enomem | 12 | out of memory | 内存溢出 |
eacces | 13 | permission denied | 拒绝许可 |
efault | 14 | bad address | 错误的地址 |
enotblk | 15 | block device required | 块设备请求 |
ebusy | 16 | device or resource busy | 设备或资源忙 |
eexist | 17 | file exists | 文件存在 |
exdev | 18 | cross-device link | 无效的交叉链接 |
enodev | 19 | no such device | 设备不存在 |
enotdir | 20 | not a directory | 不是一个目录 |
eisdir | 21 | is a directory | 是一个目录 |
einval | 22 | invalid argument | 无效的参数 |
enfile* | 23 | file table overflow | 打开太多的文件系统 |
emfile | 24 | too many open files | 打开的文件过多 |
enotty | 25 | not a tty device | 不是tty设备 |
etxtbsy | 26 | text file busy | 文本文件忙 |
efbig | 27 | file too large | 文件太大 |
enospc | 28 | no space left on device | 设备上没有空间 |
espipe | 29 | illegal seek | 非法移位 |
erofs | 30 | read-only file system | 只读文件系统 |
emlink | 31 | too many links | 太多的链接 |
epipe | 32 | broken pipe | 管道破裂 |
edom | 33 | math argument out of domain | 数值结果超出范围 |
erange | 34 | math result not representable | 数值结果不具代表性 |
edeadlk | 35 | resource deadlock would occur | 资源死锁错误 |
enametoolong | 36 | filename too long | 文件名太长 |
enolck | 37 | no record locks available | 没有可用锁 |
enosys | 38 | function not implemented | 功能没有实现 |
enotempty | 39 | directory not empty | 目录不空 |
eloop | 40 | too many symbolic links encountered | 符号链接层次太多 |
ewouldblock | 41 | same as eagain | 和eagain一样 |
enomsg | 42 | no message of desired type | 没有期望类型的消息 |
eidrm | 43 | identifier removed | 标识符删除 |
echrng | 44 | channel number out of range | 频道数目超出范围 |
el2nsync | 45 | level 2 not synchronized | 2级不同步 |
el3hlt | 46 | level 3 halted | 3级中断 |
el3rst | 47 | level 3 reset | 3级复位 |
elnrng | 48 | link number out of range | 链接数超出范围 |
eunatch | 49 | protocol driver not attached | 协议驱动程序没有连接 |
enocsi | 50 | no csi structure available | 没有可用csi结构 |
el2hlt | 51 | level 2 halted | 2级中断 |
ebade | 52 | invalid exchange | 无效的交换 |
ebadr | 53 | invalid request descriptor | 请求描述符无效 |
exfull | 54 | exchange full | 交换全 |
enoano | 55 | no anode | 没有阳极 |
ebadrqc | 56 | invalid request code | 无效的请求代码 |
ebadslt | 57 | invalid slot | 无效的槽 |
edeadlock | 58 | same as edeadlk | 和edeadlk一样 |
ebfont | 59 | bad font file format | 错误的字体文件格式 |
enostr | 60 | device not a stream | 设备不是字符流 |
enodata | 61 | no data available | 无可用数据 |
etime | 62 | timer expired | 计时器过期 |
enosr | 63 | out of streams resources | 流资源溢出 |
enonet | 64 | machine is not on the network | 机器不上网 |
enopkg | 65 | package not installed | 没有安装软件包 |
eremote | 66 | object is remote | 对象是远程的 |
enolink | 67 | link has been severed | 联系被切断 |
eadv | 68 | advertise error | 广告的错误 |
esrmnt | 69 | srmount error | srmount错误 |
ecomm | 70 | communication error on send | 发送时的通讯错误 |
eproto | 71 | protocol error | 协议错误 |
emultihop | 72 | multihop attempted | 多跳尝试 |
edotdot | 73 | rfs specific error | rfs特定的错误 |
ebadmsg | 74 | not a data message | 非数据消息 |
eoverflow | 75 | value too large for defined data type | 值太大,对于定义数据类型 |
enotuniq | 76 | name not unique on network | 名不是唯一的网络 |
ebadfd | 77 | file descriptor in bad state | 文件描述符在坏状态 |
eremchg | 78 | remote address changed | 远程地址改变了 |
elibacc | 79 | cannot access a needed shared library | 无法访问必要的共享库 |
elibbad | 80 | accessing a corrupted shared library | 访问损坏的共享库 |
elibscn | 81 | a .lib section in an .out is corrupted | 库段. out损坏 |
elibmax | 82 | linking in too many shared libraries | 试图链接太多的共享库 |
elibexec | 83 | cannot exec a shared library directly | 不能直接执行一个共享库 |
eilseq | 84 | illegal byte sequence | 无效的或不完整的多字节或宽字符 |
erestart | 85 | interrupted system call should be restarted | 应该重新启动中断的系统调用 |
estrpipe | 86 | streams pipe error | 流管错误 |
eusers | 87 | too many users | 用户太多 |
enotsock | 88 | socket operation on non-socket | 套接字操作在非套接字上 |
edestaddrreq | 89 | destination address required | 需要目标地址 |
emsgsize | 90 | message too long | 消息太长 |
eprototype | 91 | protocol wrong type for socket | socket协议类型错误 |
enoprotoopt | 92 | protocol not available | 协议不可用 |
eprotonosupport | 93 | protocol not supported | 不支持的协议 |
esocktnosupport | 94 | socket type not supported | 套接字类型不受支持 |
eopnotsupp | 95 | operation not supported on transport | 不支持的操作 |
epfnosupport | 96 | protocol family not supported | 不支持的协议族 |
eafnosupport | 97 | address family not supported by protocol | 协议不支持的地址 |
eaddrinuse | 98 | address already in use | 地址已在使用 |
eaddrnotavail | 99 | cannot assign requested address | 无法分配请求的地址 |
enetdown | 100 | network is down | 网络瘫痪 |
enetunreach | 101 | network is unreachable | 网络不可达 |
enetreset | 102 | network dropped | 网络连接丢失 |
econnaborted | 103 | software caused connection | 软件导致连接中断 |
econnreset | 104 | connection reset by | 连接被重置 |
enobufs | 105 | no buffer space available | 没有可用的缓冲空间 |
eisconn | 106 | transport endpoint | 传输端点已经连接 |
enotconn | 107 | transport endpoint | 传输终点没有连接 |
eshutdown | 108 | cannot send after transport | 传输后无法发送 |
etoomanyrefs | 109 | too many references | 太多的参考 |
etimedout | 110 | connection timed | 连接超时 |
econnrefused | 111 | connection refused | 拒绝连接 |
ehostdown | 112 | host is down | 主机已关闭 |
ehostunreach | 113 | no route to host | 没有主机的路由 |
ealready | 114 | operation already | 已运行 |
einprogress | 115 | operation now in | 正在运行 |
estale | 116 | stale nfs file handle | 陈旧的nfs文件句柄 |
euclean | 117 | structure needs cleaning | 结构需要清洗 |
enotnam | 118 | not a xenix-named | 不是xenix命名的 |
enavail | 119 | no xenix semaphores | 没有xenix信号量 |
eisnam | 120 | is a named type file | 是一个命名的文件类型 |
eremoteio | 121 | remote i/o error | 远程输入/输出错误 |
edquot | 122 | quota exceeded | 超出磁盘配额 |
enomedium | 123 | no medium found | 没有磁盘被发现 |
emediumtype | 124 | wrong medium type | 错误的媒体类型 |
ecanceled | 125 | operation canceled | 取消操作 |
enokey | 126 | required key not available | 所需键不可用 |
ekeyexpired | 127 | key has expired | 关键已过期 |
ekeyrevoked | 128 | key has been revoked | 关键被撤销 |
ekeyrejected | 129 | key was rejected by service | 关键被拒绝服务 |
eownerdead | 130 | owner died | 所有者死亡 |
enotrecoverable | 131 | state not recoverable | 状态不可恢复 |
erfkill | 132 | operation not possible due to rf-kill | 由于rf-kill而无法操作 |
暂时记录这么多,133-255全是unknown error
二、错误处理函数
许多不同的函数库都在失败时设置全局变量errno的值来指明失败原因。值得注意的是函数报告出错后必须立刻检查errno变量,因为它有可能被下一个函数调用所覆盖。
有两个非常有用的函数可以用来报告出现的错误:
#include
char *strerror(int errnum);
该函数把错误代码映射为一个字符串,对错误类型进行说明。
#include
void perror(const char *s);
该函数也把errno变量中报告的错误应为到一个字符串,并把它输出到标准错误输出流。