I read that the new process created using vfork() system call executes as a thread in the parent's address space and until the child thread doesnot calls exit() or exec() system call, the parent is blocked. So I wrote a program using 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 output as follows:
Parent
Child
Parent
Child
Parent
Child
....
....
....
I was assuming that the return statement must be calling the exit() system call internally so I was expecting the output as only
Parent
Child
Can somebody explain me why actually it is not stopping and continuously printing for infinite loop.
vfork()
is basically obsolete. It's been ripped from the latest POSIX standard, and with modern copy-on-write semantics, gains you little if any performance or memory savings. Just usefork()
. It's plenty fast, works on everything that claims to be *nix-ish, and doesn't put any restrictions on what you can do. – Nicholas Knightvfork
is still needed is on wannabe-POSIX MMU-less microcontroller-based junk. – R.. GitHub STOP HELPING ICE