Re: execv fails with EFAULT

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Steve Graegert wrote:

On 3/7/07, Prasanta Sadhukhan <Prasanta.Sadhukhan@xxxxxxx> wrote:

Hi,

When I tried the following program
void test4()
{
    printf("doing execv\n");
    if(execv("/bin/ls", "-l") == -1)
        printf("exec failed with errno %d\n", errno);
    else
        printf("exec succeed\n");
}


Prasanta,

A NULL terminated array of arguments must be passed to execv(2) as the
prototype indicates: int execv(const char *path, char *const argv[]);

For example:

#include <unistd.h>

char *cmd[] = { "ls", "-l", NULL };
int result = execv ("/bin/ls", cmd);

An error of EFAULT usually means that an argument points to an illegal address.

    \Steve

Thanks Steve... If I have a string like this sprintf(str, "-Xparameter:%d %s, value, command"), how to make it NULL terminated. Is this declaration char *cmd[] = {str, NULL} and invocation
execv(path, cmd) correct?

Regards
Prasanta


--

Steve Grägert <steve@xxxxxxxxxxxx>
Jabber    xmpp://graegerts@xxxxxxxxxx
Internet  http://eth0.graegert.com, http://blog.graegert.com
-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Assembler]     [Git]     [Kernel List]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [C Programming]     [Yosemite Campsites]     [Yosemite News]     [GCC Help]

  Powered by Linux