Search code examples
linuxshellexecos.execl

What does execl do if it can't find the command?


I already read the man page and did some googling. Couldn't find anything. Say I run execl with a path argument that doesn't actually contain the program specified in arg[0].

What will it do?


Solution

  • It returns -1 and sets errno (just try it!). It sets errno depending on the exact problem encountered.

    From the man page:

    Errors

    EACCES Search permission is denied on a component of the path prefix of filename or the name of a script interpreter. (See also path_resolution(7).)

    ENAMETOOLONG filename is too long.

    ENOENT The file filename or a script or ELF interpreter does not exist, or a shared library needed for file or interpreter cannot be found.

    ENOTDIR A component of the path prefix of filename or a script or ELF interpreter is not a directory.