Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 16 Mar 2009 20:53:49 -0700 (PDT)
From:      Nate Eldredge <neldredge@math.ucsd.edu>
To:        ron <rzo@gmx.de>
Cc:        freebsd-gnats-submit@freebsd.org, freebsd-amd64@freebsd.org
Subject:   Re: amd64/132677: error calling fork execvp
Message-ID:  <Pine.GSO.4.64.0903162039270.3173@zeno.ucsd.edu>
In-Reply-To: <200903152251.n2FMpnRk014352@www.freebsd.org>
References:  <200903152251.n2FMpnRk014352@www.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
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@math.ucsd.edu



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.GSO.4.64.0903162039270.3173>