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.
source
share