为什么这code打印两次? [英] Why does this code print two times?

查看:189
本文介绍了为什么这code打印两次?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  

可能重复:结果
  在linux GCC叉()的工作


 的#include<&stdio.h中GT;无效的主要()
{
  的printf(侨);
  叉子 ();
}

我有关于C优化的一些想法,但我不知道。希望你知道答案了。


解决方案

在code可能会打印两倍标准输出缓冲IO所以标准输出内部缓冲区将在子进程中复制和两个缓冲区刷新当每个过程中,家长和孩子,退出。

这是无关的优化。

Possible Duplicate:
Working of fork() in linux gcc

#include <stdio.h>

void main ()
{
  printf ("ciao");
  fork ();
}

I have some ideas about C optimization but I'm not sure. Hope you know the answer.

解决方案

The code will probably print "ciao" twice as standard output is buffered IO so the internal buffer for standard output will be replicated in the child process and both buffers flushed when each process, the parent and child, exits.

It is unrelated to optimization.

这篇关于为什么这code打印两次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆