什么会导致EXEC失败?接下来发生什么? [英] What can cause exec to fail? What happens next?

查看:235
本文介绍了什么会导致EXEC失败?接下来发生什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是执行exec(EXECL,execlp等)可能会失败,原因是什么?如果你犯了一个调用exec并返回,在那里不仅仅是恐慌,调用exit其他任何的最佳做法?

What are the reasons that an exec (execl,execlp, etc.) can fail? If you make a call to exec and it returns, are there any best practices other than just panicking and calling exit?

推荐答案

从<一个href=\"http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man3/exec.3.html\"><$c$c>exec(3)手册页:

EXECL() execle() execlp() execvp() execvP()函数可能会失败,并将errno任何错误的设定对于库函数指定的execve(2)的malloc(3)

The execl(), execle(), execlp(), execvp(), and execvP() functions may fail and set errno for any of the errors specified for the library functions execve(2) and malloc(3).

execv()函数可能失败并置errno为库函数指定的错误设置的execve(2)

The execv() function may fail and set errno for any of the errors specified for the library function execve(2).

再从<一个href=\"http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man2/execve.2.html%23//apple_ref/doc/man/2/execve\"><$c$c>execve(2)手册页:

错误

的execve()将失败并返回如果调用进程:

Execve() will fail and return to the calling process if:


      
  • [E2BIG] - 字节的新进程的参数列表的数量大于系统强加的限制更大。此限制是由的sysctl(3) MIB变量 KERN_ARGMAX 指定。

  •   
  • [EACCES] - 搜索权限被拒绝的路径preFIX的一个组件

  •   
  • [EACCES] - 新的工艺文件不是一个普通的文件

  •   
  • [EACCES] - 新的工艺文件模式拒绝执行权限

  •   
  • [EACCES] - 新的工艺文件是安装有执行禁用( MNT_NOEXEC 在<$文件系统C $ C>&LT; SYS / mount.h方式&gt; )

  •   
  • [EFAULT] - 新的工艺文件是不是只要在它的头大小值指示

  •   
  • [EFAULT] - 路径,argv的,或envp指向非法地址

  •   
  • [EIO] - 而从文件系统中读取数据时的I / O错误

  •   
  • [ELOOP] - 太多的符号连接都在翻译的路径遇到过。这被视为表明一个循环的符号链接。

  •   
  • [ENAMETOOLONG] - 路径名的组成部分超标 {NAME_MAX} 字符,或一个完整的路径名超过 {PATH_MAX} 字符。

  •   
  • [ENOENT] - 新的工艺文件不存在

  •   
  • [ENOEXEC] - 新进程文件具有适当的访问权限,但有一个无法识别的格式(例如,一个无效的幻数在它的头)

  •   
  • [ENOMEM] - 新的工艺要求比被设定的最大值(允许更多的虚拟内存使用getrlimit(2))。

  •   
  • [ENOTDIR] - 路径preFIX的组成部分不是一个目录

  •   
  • [ETXTBSY] - 新工艺文件是当前打开的书面或通过一些过程中阅读纯过程(共享文本)文件

  •   
  • [E2BIG] - The number of bytes in the new process's argument list is larger than the system-imposed limit. This limit is specified by the sysctl(3) MIB variable KERN_ARGMAX.
  • [EACCES] - Search permission is denied for a component of the path prefix.
  • [EACCES] - The new process file is not an ordinary file.
  • [EACCES] - The new process file mode denies execute permission.
  • [EACCES] - The new process file is on a filesystem mounted with execution disabled (MNT_NOEXEC in <sys/mount.h>).
  • [EFAULT] - The new process file is not as long as indicated by the size values in its header.
  • [EFAULT] - Path, argv, or envp point to an illegal address.
  • [EIO] - An I/O error occurred while reading from the file system.
  • [ELOOP] - Too many symbolic links were encountered in translating the pathname. This is taken to be indicative of a looping symbolic link.
  • [ENAMETOOLONG] - A component of a pathname exceeded {NAME_MAX} characters, or an entire path name exceeded {PATH_MAX} characters.
  • [ENOENT] - The new process file does not exist.
  • [ENOEXEC] - The new process file has the appropriate access permission, but has an unrecognized format (e.g., an invalid magic number in its header).
  • [ENOMEM] - The new process requires more virtual memory than is allowed by the imposed maximum (getrlimit(2)).
  • [ENOTDIR] - A component of the path prefix is not a directory.
  • [ETXTBSY] - The new process file is a pure procedure (shared text) file that is currently open for writing or reading by some process.

的malloc()是少了很多复杂,只使用 ENOMEM 。从<一个href=\"http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man3/malloc.3.html%23//apple_ref/doc/man/3/malloc\"><$c$c>malloc(3)手册页 :

malloc() is a lot less complicated, and uses only ENOMEM. From the malloc(3) man page:

如果成功,释放calloc()的malloc() realloc()的 reallocf() valloc()函数返回一个指向分配的内存。如果有错误,他们返回 NULL 指针并且置错误号 ENOMEM

If successful, calloc(), malloc(), realloc(), reallocf(), and valloc() functions return a pointer to allocated memory. If there is an error, they return a NULL pointer and set errno to ENOMEM.

这篇关于什么会导致EXEC失败?接下来发生什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆