This is program for vfork(). This program creates multiple parent and child processes and return -1 at the end (mean OS cannot create another process). Why such behaviour happens?
#include<stdio.h>
void main()
{
int pid;
pid=vfork();
printf("pid=%d\n",pid);
if(pid==0)
{
printf("hello\n");
}
}
(1) This creates a single child.
(2) With
vforkthe child shares memory with the parent until eitherexecor_exitare called. You call neither.(3) The parent's execution is suspended until the child calls
execor_exit.So basically your example is FUBAR. The point of
vfork(if there really is one these days) is to provide a fastforkmechanism that will immediatelyexecanother program. The need for this has been vastly diminished with the copy-on-write behavior of regularfork.