且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为什么这code打印两次?

更新时间:2023-02-05 19:47:53

在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.