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


当前回答

它的意思是:

未找到文件或目录。

其他回答

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

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

#include <errno.h> 
#include <stdio.h> 
#include <stdlib.h> 

int main(int i, char *c[]) { 
  if (i != 2)  
    fprintf(stderr, "Usage: perror errno\n"); 
  else { 
    errno = atoi(c[1]); 
    perror(""); 
  } 
  exit(0); 
}    

适用于Solaris。 Cc perror.c -o perror <<使用这一行来编译它

您可以使用以下一行程序检索系统上的errno值的完整列表,而不是对所得到的任何错误代码运行perror:

cpp -dM /usr/include/errno.h | grep 'define E' | sort -n -k

我在我的.bashrc文件中有以下函数-它从头文件中查找errno值(可以是/usr/include/errno.h, /usr/include/linux/errno.h,等等,等等)

如果头文件安装在机器上,它就可以工作;-)

通常头文件有一个错误+接下来是注释中的解释;以下内容:

./asm-generic/errno-base.h:#define EAGAIN 11 /*重试*/

function errno()
{
    local arg=$1

    if [[ "x$arg" == "x-h" ]]; then
        cat <<EOF
        Usage: errno <num>
        Prints text that describes errno error number
        EOF
    else
        pushd /usr/include
        find . -name "errno*.h" | xargs grep   "[[:space:]]${arg}[[:space:]]"
        popd
    fi
}