fork(5) download
  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #include <sys/wait.h>
  4.  
  5. int main() {
  6. int n = 1;
  7. if(fork() == 0) {
  8. printf("child");
  9. n = n + 1;
  10. exit(0);
  11. }
  12. n = n + 2;
  13. printf("%ld: %d\n", (long)getpid(), n);
  14. wait(0);
  15. return 0;
  16. }
  17.  
Success #stdin #stdout 0s 9432KB
stdin
Standard input is empty
stdout
child23891: 3