Vfork () system call

I read that a new process created using the vfork () system call is executed as a thread in the parent address space, and until the child thread calls the exit () or exec () system call, the parent block is blocked. So I wrote a program using the vfork () system call

#include <stdio.h>  
#include <unistd.h>

int main()  
 {  
      pid_t pid;  
      printf("Parent\n");  
      pid = vfork();  
      if(pid==0)  
      {  
          printf("Child\n");  
      }  
      return 0;  
  }

I got the result as follows:

 Parent  
 Child  
 Parent  
 Child  
 Parent  
 Child  
 ....  
 ....  
 ....

I assumed that the return statement should call the exit () system call internally, so I expected the output to only be

Parent  
Child

Can someone explain to me why it really doesn't stop and constantly prints an endless loop.

+5
source share
1 answer

vfork:

vfork() , fork (2), , undefined, , vfork(), , pid_t, vfork() , vfork(), _exit (2) exec (3).

( POSIX , () , Linux).

printf , undefined.

+5

All Articles