-
-
Save caigen/7197190 to your computer and use it in GitHub Desktop.
fork面试题通常画二叉树解,理解内核的实现则秒解。如下代码输出2+2+2=8个'-'是因为缓冲区被复制到子进程。使用fflush或'\n'则2+4=6个'-'。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <unistd.h> | |
| int main(int argc, char *argv[]) | |
| { | |
| for (int i = 0; i < 2; i++) { | |
| fork(); | |
| printf("-"); | |
| // fflush(stdout); | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment