关于Linux中的错误号码

有什么链接或材料,我可以了解更多关于Linux中不同的错误号码?

目前在errno中,每个错误编号都有一行,但是我想知道发生特定错误的条件或机会(更简短的描述,

例如

EADDRNOTAVAIL 99 /* Cannot assign requested address */ 

上面的错误发生时套接字试图绑定到本地不存在的机器上的IP地址..同样,所有其他错误是有任何维基或材料的详细信息?

那么,由于错误通常是在做某事的时候发生的,所以最好的办法就是查看man page来查找“something”。

例如,如果你从你的fscanf()调用中得到一个34的errno号,你首先要做的是:

 grep 34 $(find /usr/include -name '*errno*h') 

找出错误是什么:

 /usr/include/bits/errno.h:#define ERANGE 34 /* Math result not representable. */ /usr/include/asm-generic/errno-base.h:#define ERANGE 34 /* Math result not ... */ 

然后,查看fscanf()man页,可以看到:

 ERANGE - The result of an integer conversion would exceed the size that can be stored in the corresponding integer type. 

你会(希望)能够从那里弄清楚。

如果你想要一个错误列表(简要)的描述,修改上面的grep ,如下所示:

 grep define $(find /usr/include -name '*errno*h') | less 

并浏览输出。

而且,如果你仍然不知道这个错误是什么引起的(描述有点简单,我会同意),我只是把它(例如, EADDRNOTAVAIL )放到右上角的那个小对话框中你的浏览器1 ,你会得到这样的 (或许多其他精彩的网页):

无法分配请求的地址
您正尝试bind(2)到本地的本地地址。 例如,如果一台机器的IP地址是127.0.0.11.2.3.4而你试图绑定到1.2.3.5 ,你将会得到这个错误。 检查以确保您尝试绑定的地址存在于您要绑定的机器上。
如果您正在执行“预先绑定连接”,则会出现此错误,您将首先绑定到本地端口,然后使用套接字执行出站连接。 如果本地端口已经连接到给定的远程IP和端口(即已经有一个相同的socketpair),那么你会收到这个错误(在Linux上的值为99)。
共4页链接到EADDRNOTAVAIL
– 绑定(2)
– 连接(2)
– setsockopt(2)
– 数据包(7)

继续,尝试与其他错误值,也不是太糟糕。


1正在使用Firefox,对不对? 🙂

错误代码是相当通用的,只在特定功能的上下文中才有意义。 所以在学习所有的错误代码方面没有多大的优势,因为它们对于不同的功能可能意味着微妙的差别,所以不管怎样,都必须有不同的处理方式。

函数手册页中的“ERRORS”部分将告诉你它的返回值或errno可能有哪些代码,以及它们为什么会出现。

如果是GLIBC,请尝试在printf()语句中使用%m

 #include <errno.h> ... int fh = fopen(...); if (0 > fh) printf("Couldn't open the file: %d, %m\n", errno); 

很有用。

它的API specfic。 我还没有听说过一个通用的错误列表。 但是:

 Many functions provide an error number in errno, which has type int and is defined in <errno.h>. 

所以你可以看一下头文件errno.h 。 同样, Glib具有不同的错误报告代码。

编辑:好吧,如果你已经知道错误代码,那么你总是可以谷歌获得更多的信息,如果你发现手册页不尽如人意。

正如其他海报所暗示的那样,解释错误在上下文中真正含义的最佳来源是适当的手册页。 对于网络协议,适当的手册页可能不是系统调用; 对于IP套接字,试试ip(7),这给了更多的信息:

  EADDRNOTAVAIL A nonexistent interface was requested or the requested source address was not local. 

在tcp(7)和udp(7)中描述了更多的错误代码。

这个程序也可以做的伎俩..

 #include<stdio.h> #include<string.h> int main() { int i= 0 ; for ( i = 0 ; i<=132; i++ ) { printf("no %d == %s \n", i , strerror(i)); } } 
 no 0 == Success no 1 == Operation not permitted no 2 == No such file or directory no 3 == No such process no 4 == Interrupted system call no 5 == Input/output error no 6 == No such device or address no 7 == Argument list too long no 8 == Exec format error no 9 == Bad file descriptor no 10 == No child processes no 11 == Resource temporarily unavailable no 12 == Cannot allocate memory no 13 == Permission denied no 14 == Bad address no 15 == Block device required no 16 == Device or resource busy no 17 == File exists no 18 == Invalid cross-device link no 19 == No such device no 20 == Not a directory no 21 == Is a directory no 22 == Invalid argument no 23 == Too many open files in system no 24 == Too many open files no 25 == Inappropriate ioctl for device no 26 == Text file busy no 27 == File too large no 28 == No space left on device no 29 == Illegal seek no 30 == Read-only file system no 31 == Too many links no 32 == Broken pipe no 33 == Numerical argument out of domain no 34 == Numerical result out of range no 35 == Resource deadlock avoided no 36 == File name too long no 37 == No locks available no 38 == Function not implemented no 39 == Directory not empty no 40 == Too many levels of symbolic links no 41 == Unknown error 41 no 42 == No message of desired type no 43 == Identifier removed no 44 == Channel number out of range no 45 == Level 2 not synchronized no 46 == Level 3 halted no 47 == Level 3 reset no 48 == Link number out of range no 49 == Protocol driver not attached no 50 == No CSI structure available no 51 == Level 2 halted no 52 == Invalid exchange no 53 == Invalid request descriptor no 54 == Exchange full no 55 == No anode no 56 == Invalid request code no 57 == Invalid slot no 58 == Unknown error 58 no 59 == Bad font file format no 60 == Device not a stream no 61 == No data available no 62 == Timer expired no 63 == Out of streams resources no 64 == Machine is not on the network no 65 == Package not installed no 66 == Object is remote no 67 == Link has been severed no 68 == Advertise error no 69 == Srmount error no 70 == Communication error on send no 71 == Protocol error no 72 == Multihop attempted no 73 == RFS specific error no 74 == Bad message no 75 == Value too large for defined data type no 76 == Name not unique on network no 77 == File descriptor in bad state no 78 == Remote address changed no 79 == Can not access a needed shared library no 80 == Accessing a corrupted shared library no 81 == .lib section in a.out corrupted no 82 == Attempting to link in too many shared libraries no 83 == Cannot exec a shared library directly no 84 == Invalid or incomplete multibyte or wide character no 85 == Interrupted system call should be restarted no 86 == Streams pipe error no 87 == Too many users no 88 == Socket operation on non-socket no 89 == Destination address required no 90 == Message too long no 91 == Protocol wrong type for socket no 92 == Protocol not available no 93 == Protocol not supported no 94 == Socket type not supported no 95 == Operation not supported no 96 == Protocol family not supported no 97 == Address family not supported by protocol no 98 == Address already in use no 99 == Cannot assign requested address no 100 == Network is down no 101 == Network is unreachable no 102 == Network dropped connection on reset no 103 == Software caused connection abort no 104 == Connection reset by peer no 105 == No buffer space available no 106 == Transport endpoint is already connected no 107 == Transport endpoint is not connected no 108 == Cannot send after transport endpoint shutdown no 109 == Too many references: cannot splice no 110 == Connection timed out no 111 == Connection refused no 112 == Host is down no 113 == No route to host no 114 == Operation already in progress no 115 == Operation now in progress no 116 == Stale NFS file handle no 117 == Structure needs cleaning no 118 == Not a XENIX named type file no 119 == No XENIX semaphores available no 120 == Is a named type file no 121 == Remote I/O error no 122 == Disk quota exceeded no 123 == No medium found no 124 == Wrong medium type no 125 == Operation canceled no 126 == Required key not available no 127 == Key has expired no 128 == Key has been revoked no 129 == Key was rejected by service no 130 == Owner died no 131 == State not recoverable no 132 == Unknown error 132