Chinaunix首页 | 论坛 | 博客
  • 博客访问: 359593
  • 博文数量: 168
  • 博客积分: 6895
  • 博客等级: 准将
  • 技术积分: 1726
  • 用 户 组: 普通用户
  • 注册时间: 2010-03-12 23:01
文章分类

全部博文(168)

文章存档

2011年(6)

2010年(162)

我的朋友

分类: LINUX

2011-07-22 12:15:59

Hi boys, do you know how many processes the following codes produce? It is 2^5.
So we can get a conclusion which you have n amounts for-statement and you will
get 2^n processes. If you don't know the reason, send me a mail, which i will
describe the reasons in details ;-)
 
#include
#include
#include
int main(void)
{
 int i = 0;
 pid_t j;

 for (i = 0; i < 5; i++) {
  if (0 > (j = fork())) {
   fprintf(stderr, "Fork Error!\n");
   return 1;
  }
  if (0 == j) {
   fprintf(stdout, "child: %d", getpid());
  } else {
   fprintf(stdout, "parent: %d\n", getpid());
  }
 }
 return 0;
}
阅读(542) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~