LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-15-2005, 05:30 AM   #1
MD3
Member
 
Registered: Apr 2004
Location: Italy
Distribution: Gentoo
Posts: 81

Rep: Reputation: 15
execve alwayse produces EFAULT


hi!
i wrote this program: http://lagnusi.net/pub/rungid.c

when i run it, the function
Code:
execve(argv[1], execve_process_argsv, execve_process_envp);
always returns -1 (error) end sets errno to EFAULT, as i can see through
Code:
case EFAULT:
            perror("The filename provided points outside your accesible address space\n");
            break;
why? and how can i avoid this?


thanks
 
Old 06-15-2005, 09:33 AM   #2
MD3
Member
 
Registered: Apr 2004
Location: Italy
Distribution: Gentoo
Posts: 81

Original Poster
Rep: Reputation: 15
resolved this! there were an argument missing! the function wants the second parameter to be an array of strings where the first is the program name and the last is (char *)0


now... there's the last little thing to examine:
*the program launched is executed 2 times*
as if it was wxecuted normally by the forked process but also by the original process!
someone can explain me why?
 
Old 06-15-2005, 10:15 AM   #3
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
Code:
   my_child_pid = fork();

   if(my_child_pid == -1) {
      perror("Unable to allocate enough memory to fork\n");
      _exit(errno);
   }

   execve_return = execve(argv[1], execve_process_argsv, execve_process_envp);
Because you're calling execve() in the parent and the child. You want to do something like: if(!child_pid) execve(...)
 
Old 06-15-2005, 01:04 PM   #4
MD3
Member
 
Registered: Apr 2004
Location: Italy
Distribution: Gentoo
Posts: 81

Original Poster
Rep: Reputation: 15
Quote:
Originally posted by itsme86
Code:
   my_child_pid = fork();

   if(my_child_pid == -1) {
      perror("Unable to allocate enough memory to fork\n");
      _exit(errno);
   }

   execve_return = execve(argv[1], execve_process_argsv, execve_process_envp);
Because you're calling execve() in the parent and the child. You want to do something like: if(!child_pid) execve(...)
you're great.. now it works perfectly! thanks
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
strace only shows execve Quigi Linux - Software 2 10-27-2005 01:44 PM
very urgent!details about execve()??????? vrdhananjay Programming 11 02-08-2005 05:07 PM
Linux syscall 11 (execve) Genjix Programming 1 12-29-2004 11:38 PM
Using execve() not working cxel91a Programming 3 09-03-2003 06:26 AM
fork() and execve() Alf829 Programming 3 08-02-2003 10:18 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:42 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration