fork download
  1. #include <unistd.h>
  2. #include <stdio.h>
  3. #include <sys/types.h>
  4. int main() {
  5. printf("%d: Common code1\n", getpid());
  6. fflush(stdout);
  7. if (fork() != 0) {
  8. printf("%d: Parent code\n", getpid());
  9. } else {
  10. printf("%d: Child code\n", getpid());
  11. }
  12. printf("%d: Common code\n", getpid());
  13. }
Runtime error #stdin #stdout 0s 2052KB
stdin
Standard input is empty
stdout
7861: Common code1
7861: Parent code
7861: Common code
7870: Child code
7870: Common code