当调用execl(…)时,我得到一个errno=2。这是什么意思?我怎么知道这个errno的意思?


当前回答

当您使用strace(在Linux上)运行二进制文件时,它将输出系统调用的返回值以及错误数的含义。这可能有时对你有用。

其他回答

这比在errno.h中查找代码要快,比这里发布的大多数解决方案都要短,并且不需要安装第三方工具:

perl -E 'say $!2 =转变'

收益率

没有这样的文件或目录

错误码2表示“未找到文件/目录”。通常,可以使用perror函数打印人类可读的字符串。

当您使用strace(在Linux上)运行二进制文件时,它将输出系统调用的返回值以及错误数的含义。这可能有时对你有用。

我使用以下脚本:

#!/usr/bin/python

import errno
import os
import sys

toname = dict((str(getattr(errno, x)), x) 
              for x in dir(errno) 
              if x.startswith("E"))
tocode = dict((x, getattr(errno, x)) 
              for x in dir(errno) 
              if x.startswith("E"))

for arg in sys.argv[1:]:
    if arg in tocode:
        print arg, tocode[arg], os.strerror(tocode[arg])
    elif arg in toname:
        print toname[arg], arg, os.strerror(int(arg))
    else:
        print "Unknown:", arg

Call

perror("execl");

以防出错。

示例:

if(read(fd, buf, 1)==-1) {
    perror("read");
}

errno(3)和perror(3)的手册页也很有趣……