fork(7) 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. if (fork() != 0) {
  7. printf("%d: Parent code\n", getpid());
  8. } else {
  9. printf("%d: Child code\n", getpid());
  10. }
  11. printf("%d: Common code\n", getpid());
  12. }
Runtime error #stdin #stdout 0s 2052KB
stdin
Standard input is empty
stdout
27889: Common code1
27889: Parent code
27889: Common code
27889: Common code1
27892: Child code
27892: Common code