[uClinux-dev] A strange problem of vfork

Erik Andersen andersen at codepoet.org
Thu Nov 15 23:09:35 EST 2001


On Fri Nov 16, 2001 at 11:59:21AM +0800, SuCC wrote:
> Hi,
>    I encounter a strange situation about using vfork() in uClinux-2.4.0 on ARM7!!
>    We know the return values of vfork() are :
>          0      : child process
>         -1      : vfork error , and errno will fill a error type
>         other : parent process 
> 
>    But I have a program(pptp server) which will call vfork like
>     pid = vfork();
>     if(pid == 0) printf("I am child!!");
>     else if(pid == -1) printf("errno=%d",errno);
>     else printf("I am parent!!");
> 
>     When I run the program.....the result is only show

Your vforked process needs to exit or call exec...  
Try something like this following.

int main(void)
{
    pid_t pid;
    int status, wpid;
    char *argv[] = {
        "/bin/ls",
        NULL,
    };

    if ((pid = vfork()) == 0) {
        printf("I'm the child process...\n");
        execvp(argv[0], argv);
        _exit(0);
    }

    printf("I'm the parent process.\n");
    while (1) {
        wpid = wait(&status);
        if (wpid > 0 && wpid != pid) {
            continue;
        }
        if (wpid == pid)
            break;
    }

    printf("Child process exited.\nGoodbye.\n");
    return EXIT_SUCCESS;
}

 -Erik

--
Erik B. Andersen             http://codepoet-consulting.com/
--This message was written using 73% post-consumer electrons--
This message resent by the uclinux-dev at uclinux.org list server http://www.uClinux.org/
This message resent by the uclinux-dev at uclinux.org list server http://www.uClinux.org/



More information about the uClinux-dev mailing list