amd64/132677: error calling fork execvp

Nate Eldredge neldredge at math.ucsd.edu
Mon Mar 16 21:14:42 PDT 2009


On Sun, 15 Mar 2009, ron wrote:

> hello,
>
> calling execvp(2) works fine.
>
> however calling
>
> pid = fork()
> if (pid == 0)
>  execvp(2)
>
> returns error 22 (invalid value)
>
> calling
>
> pid = fork()
> if (pid == 0)
>  execve(3)
>
> works fine

Can you be more specific?  In particular, could you send a complete source 
that can be compiled and run, and that shows the problem?

I can't reproduce a problem here.  I am running 7.1 on amd64, and the 
following program works as expected.

#include <unistd.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <stdlib.h>

int main(void) {
   pid_t pid;
   pid = fork();
   if (pid == 0) {
     char *argv[] = { "echo", "Hello, world!", NULL };
     execvp("echo", argv);
     perror("execvp failed");
     _exit(1);
   } else if (pid > 0) {
     int status;
     if (waitpid(pid, &status, 0) == -1) {
       perror("waitpid");
       exit(1);
     }
     if (WIFEXITED(status))
       printf("Child exited with status %d\n", WEXITSTATUS(status));
     else if (WIFSIGNALED(status))
       printf("Child killed by signal %d\n", WTERMSIG(status));
     else
       printf("Impossible status!\n");
   } else if (pid < 0) {
     perror("fork");
     exit(1);
   }
   return 0;
}

The output is:
Hello, world!
Child exited with status 0

Perhaps there is something wrong in a different part of your test program.

-- 

Nate Eldredge
neldredge at math.ucsd.edu


More information about the freebsd-amd64 mailing list