一般快速fork()说明(General Quick fork() explanation)

编程入门 行业动态 更新时间:2024-10-25 18:34:56
一般快速fork()说明(General Quick fork() explanation)

假设我们有这样的事情:

printf("A"); fork(); printf("B");

是输出吗?

1)ABAB 2)ABB

你能解释一下吗?

suppose if we have something like this:

printf("A"); fork(); printf("B");

Is the output going to be

1) ABAB 2) ABB

Can you please explain?

最满意答案

正确的答案是它取决于stdout的缓冲模式,其他答案似乎忽略了。

当您使用未刷新的缓冲区进行分叉然后在两个进程中继续使用stdio(而不是在子进程中通常的快速执行或_exit )时,fork时缓冲区中的内容可以打印两次,每次一次处理。

The right answer is that it depends on the buffering mode of stdout, which the other answers seem to be ignoring.

When you fork with unflushed buffers and then continue using stdio in both processes (instead of the usual quick execve or _exit in the child process), the stuff that was in the buffer at the time of the fork can be printed twice, once by each process.

更多推荐

本文发布于:2023-08-04 08:57:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1413163.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:快速   fork   General   Quick   explanation

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!