vfork always fail problem

Matthias Andree matthias.andree@gmx.de
Fri May 14 08:57:00 GMT 2010


Am 14.05.2010, 06:29 Uhr, schrieb Huang Bambo:

> [Bambo@bambo-notebook 4.4.4]$ cat tvfork.c
> #include <sys/types.h>
> #include <unistd.h>
> #include <stdio.h>
>
> int main(void)
> {
>         pid_t pid = vfork();
>         if ( pid > 0 )
>         {
>                 printf("I'm chield.\n");
>                 _exit(0);
>         }
>         else if ( pid == 0 )
>         {
>                 printf("I'm parent");
>         }

You've got these swapped. pid == 0 means child, > 0 means parent (so that  
it directly has the PID of its child and can later call waitpid()).

You later wrote you've issues with the path; does the same happen if you  
use "fork" rather than "vfork"?  vfork()ed child processes must not do  
anything but modify a variable of type pid_t, call _exit() or exec*().

-- 
Matthias Andree

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple



More information about the Cygwin mailing list