[root@server home]# cat vfork.c
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
int main (int argc,char *argv[])
{
pid_t pid;
int count=0;
pid=vfork();
if(pid<0){
perror("vfork");
}
if(pid==0){
sleep(3);
count++;
printf("i am son,count:%d\n",count);
exit(0);
}else if(pid>0){
count++;
printf("i am father,count:%d\n",count);
}
return 0;
}
[root@server home]# gcc -o vfork vfork.c
[root@server home]# ./vfork
i am son,count:1
i am father,count:2