I am trying the following C code:
int main() { printf(\"text1\\n\"); fork(); printf(\"text2\\n\"); return 0; }
I was expect
It is because forked process starts after fork, not from very beginning. exec starts process from entry point and will print what you expect.
fork
exec