[uClinux-dev] A strange problem of vfork

SuCC sujz at cad.csie.ncku.edu.tw
Fri Nov 16 09:07:39 EST 2001


But vfork will block parent process until child process call execvp or exit
So my result is shoe that
It run the parent process befiore I saw that does it fork a child success or
failed!!
(exactly , I never saw it is success ot failed)
------------------------------------------------------
Sincerely,
Chien-Chung Su
Intelligent System/Media Processing Lab.
Department of CSIE, NCKU
http://ismp.csie.ncku.edu.tw

----- Original Message -----
From: "Erik Andersen" <andersen at codepoet.org>
To: "SuCC" <sujz at cad.csie.ncku.edu.tw>
Cc: <uclinux-dev at uclinux.org>
Sent: Friday, November 16, 2001 12:09 PM
Subject: Re: [uClinux-dev] A strange problem of vfork


> 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/
>
>


This message resent by the uclinux-dev at uclinux.org list server http://www.uClinux.org/



More information about the uClinux-dev mailing list