一、vfork函数
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
//vfork函数
int main()
{
int cnt = 0;
pid_t pid;
pid = vfork();
//father process
if(pid > 0)
{
while(1)
{
printf("cnt = %d\n",cnt);
printf("father process pid is %d\n",getpid());
sleep(1);
}
}
//child process
else if(pid == 0)
{
while(1)
{
cnt ++;
printf("child process is %d\n",getpid());
sleep(1);
printf("cnt = %d\n",cnt);
if(cnt == 3)
{
exit(0);
//_exit(0);
//_Exit(0);
}
}
}
return 0;
}
二、进程退出