关于vfork()解决方法

关于vfork()
今天学习vfork的时候,了解到vfork出来的子进程是占用父进程的空间,于是写了下面的测试
int main()
{
    int a=0;
    int value;

    pid_t pid;
    if((pid= vfork()) < 0)
        printf("error vfork\n");
    else if(pid == 0){   
        printf("child ....%d\n");
        return 0;
    }   
    else{
        printf("parent .......\n");
    }   
    return 0;
}

我想得是,由于vfork后父进程必须等待子进程退出后才能运行,那么如果vfork直接返回了,肯定会出问题,但我不确定是什么问题,于是做了测试结果发现输出如下:
child vfork
parent vfork
child vfork
parent vfork
.....
error vfork
也就是说,vfork返回之后,看似进入了一个死循环,不停的fork直到可能是达到了进程数量的上限,然后vfork返回了一个错误,程序才退出,希望有人能帮忙解释下,不是很明白
------解决方案--------------------
according to APUE:

The vfork function is intended to create a new process when the purpose of the new process is to exec a new program. 

The vfork function creates the new process, just like fork, without copying the address space of the parent into the child, as the child won't reference that address space; the child simply calls exec (or exit) right after the vfork. 

Instead, while the child is running and until it calls either exec or exit, the child runs in the address space of the parent.

vfork guarantees that the child runs first, until the child calls exec or exit.When the child calls either of these functions, the parent resumes. (This can lead to deadlock if the child depends on further actions of the parent before calling either of these two functions.) 
------解决方案--------------------
引用:
谢谢,我也是看的aupe,你说的这些我了解,我只是想有人能具体解释一下子线程返回时发生了什么,是什么原因导致这种死循环,具体的过程是什么。。。。

u are welcome!

I don't want to know what under the hood may look like coz it'not worth my time. I follow manual:

vfork man page:

vfork() differs from fork(2) in that the calling thread is suspended
       until the child terminates (either normally, by calling _exit(2), or
       abnormally, after delivery of a fatal signal), or it makes a call to
       execve(2).  Until that point, the child shares all memory with its
       parent, including the stack.  The child must not return from the
       current function or call exit(3), but may call _exit(2).


If I have to answer why that happened, I would say the behavior is undefined and could vary.

I am sure “大神” can help you here...