主题 : 使用vfork()后,结束时用return 0,带来的不解 复制链接 | 浏览器收藏 | 打印
级别: 新手上路
UID: 71701
精华: 0
发帖: 4
金钱: 20 两
威望: 4 点
贡献值: 0 点
综合积分: 8 分
注册时间: 2012-06-09
最后登录: 2012-09-11
楼主  发表于: 2012-09-09 20:39

 使用vfork()后,结束时用return 0,带来的不解

#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>
main()
{
  pid_t pid;
  int count=0;
  pid=vfork();
  count++;  
  printf("count=%d, pid=%d\n",count,getpid());
  return(0);
}
运行出现count=1,pid=25127
  count=1, pid=25126 后又显示“段错误”
尝试把retrurn(0); 改为 exit(0);之后运行结果 count=1;pid=25145
  count=2;pid=25144
查看了有关return() 和 exit()还是不理解,求解释!!!!!!