2010-07-21 47 views
5

有什麼鏈接或材料可以在Linux中瞭解有關錯誤編號的更多信息?關於Linux中的錯誤編號

目前在人類錯誤號我得到每個錯誤數目的單個線,但我想知道其中發生特定錯誤條件或機會(在短詞的更詳細描述)

對於例如

EADDRNOTAVAIL 99 /* Cannot assign requested address */ 

上述錯誤在套接字試圖綁定到IP地址,其未在本地機器呈現..類似地,對於所有其他錯誤是有詳細信息的任何頁面添加內容或材料發生?

回答

3

錯誤代碼是相當通用的,並且僅在特定功能的上下文中才有意義。所以在學習所有的錯誤代碼方面沒有太多優勢,因爲它們可能意味着對於不同的功能有微妙的不同,並且必須以不同的方式進行處理。

函數手冊頁中的「錯誤」部分將告訴您哪些代碼可用於返回值或errno以及它們出現的原因。

+0

是的,我同意你的亞歷克斯......但每一個男人頁面錯誤部分仍然具有相同的一行。 .. :( – codingfreak 2010-07-21 03:39:05

+0

@codingfreak其中許多可能是相同的,但不一定,例如'man 2 open'和'man 2 pthread_create'的'EPERM'是不同的,必須以不同的方式處理。 – 2010-07-21 03:46:09

0

它的API specfic。我還沒有聽說過一個通用的錯誤列表。然而:

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

所以你可以看看頭文件errno.h。 同樣Glib有不同的錯誤報告代碼。

編輯: 那麼如果你已經知道錯誤代碼,那麼你總是可以谷歌獲得關於該錯誤的更多信息,如果你發現手冊頁不滿意。

+0

但我更感興趣的錯誤在人errno中指定的錯誤不是特定於任何第三方應用程序...像glib – codingfreak 2010-07-21 03:38:06

+0

@codingfreak:您可以查看文件errno.h的鏈接。 – 2010-07-21 03:42:01

0

如果是GLIBC,嘗試在一個printf()語句中使用%m

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

非常有用的。

+0

詳細說明源錯誤代碼的所有位置將是一個巨大的,並不斷過時的日期努力:您是否正在編寫自己的驅動程序,並希望確保您正在選擇正確的錯誤代碼? – Jamie 2010-07-21 03:43:35

9

好吧,由於錯誤通常發生在做某事時,最好的辦法就是查找man頁面來獲得「某些東西」。

例如,如果你回來從你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 ... */ 

然後,找在man頁面爲fscanf(),您會看到:

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)塞進那個小小的對話框中您的瀏覽器的右上角,你會回來像this(或許多其他精彩頁):

無法分配請求地址
您正在試圖bind(2)到本地地址這不是本地的。例如,如果某臺計算機的IP地址是127.0.0.11.2.3.4,並且您嘗試綁定到1.2.3.5,則會出現此錯誤。檢查以確保您嘗試綁定的地址存在於您嘗試綁定它的計算機上。
如果您正在執行「預先綁定連接」,您首先綁定到本地端口,然後使用套接字執行出站連接,則也會出現此錯誤。如果本地端口已連接到給定的遠程IP和端口(即已有相同的套接字對),則會收到此錯誤(Linux上的值爲99)。
4頁面鏈接到EADDRNOTAVAIL
          -  綁定(2)
          -  連接(2)
          -   setsockopt的(2)
          -  包(7)

來吧,與其他錯誤值嘗試爲好,這不是太糟糕了。


使用的是Firefox,對不對? :-)

+0

Firefox它是!很好的解釋btw。 – 2010-07-21 03:49:15

+0

感謝您的好解釋:) – codingfreak 2010-07-21 05:41:39

0

正如其他海報的建議,解碼錯誤真正意義上下文的最佳來源是適當的手冊頁。對於網絡協議,適當的手冊頁可能不是系統調用;爲IP套接字,IP嘗試(7),其給出一點點的更多信息:

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

更多的錯誤代碼在TCP中描述(7)和UDP(7)。

+0

感謝您的輸入 – codingfreak 2010-07-21 05:40:50

0

這個程序還可以做的伎倆..

#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 
+0

只是好奇 - 爲什麼選擇132? – paxdiablo 2010-07-21 11:39:10