From: Prasanta Sadhukhan <Prasanta.Sadhukhan@Sun.COM>
To: Steve Graegert <graegerts@gmail.com>
Cc: linux-c-programming@vger.kernel.org
Subject: Re: execv fails with EFAULT
Date: Wed, 07 Mar 2007 18:44:03 +0530 [thread overview]
Message-ID: <45EEBA9B.9030903@sun.com> (raw)
In-Reply-To: <6a00c8d50703070446s26ddb847uae5697ed797a2ff0@mail.gmail.com>
Steve Graegert wrote:
> On 3/7/07, Prasanta Sadhukhan <Prasanta.Sadhukhan@sun.com> 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@graegert.com>
> Jabber xmpp://graegerts@jabber.org
> 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@vger.kernel.org
> 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@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2007-03-07 13:14 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-03-07 11:54 execv fails with EFAULT Prasanta Sadhukhan
2007-03-07 12:46 ` Steve Graegert
2007-03-07 13:14 ` Prasanta Sadhukhan [this message]
2007-03-07 13:50 ` Steve Graegert
2007-03-07 16:58 ` Glynn Clements
2007-03-07 14:20 ` Mathieu Dube
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=45EEBA9B.9030903@sun.com \
--to=prasanta.sadhukhan@sun.com \
--cc=graegerts@gmail.com \
--cc=linux-c-programming@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).