Need to know how fork works?

前端 未结 7 1883
[愿得一人]
[愿得一人] 2020-12-15 13:32

I am trying the following C code:

int main()
{
    printf(\"text1\\n\");
    fork();
    printf(\"text2\\n\");
    return 0;
}

I was expect

7条回答
  •  青春惊慌失措
    2020-12-15 14:04

    It is because forked process starts after fork, not from very beginning. exec starts process from entry point and will print what you expect.

提交回复
热议问题