Skip to content

Instantly share code, notes, and snippets.

@shihyu
Created November 24, 2018 15:37
Show Gist options
  • Select an option

  • Save shihyu/10f7021b4a0f277b1cf9d045a8d41e86 to your computer and use it in GitHub Desktop.

Select an option

Save shihyu/10f7021b4a0f277b1cf9d045a8d41e86 to your computer and use it in GitHub Desktop.

Revisions

  1. shihyu created this gist Nov 24, 2018.
    30 changes: 30 additions & 0 deletions fork_test.c
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    #include <sys/types.h>
    #include <unistd.h>

    int fork_1()
    {
    int childpid;
    int i;

    if (fork() == 0) {
    //child process
    for (i = 1; i <= 20; i++) {
    printf("This is child process\n");
    }
    } else {
    //parent process
    for (i = 1; i <= 2; i++) {
    printf("This is parent process\n");
    }
    }

    printf("step2 after fork() !! pid=%d\n\n", getpid());

    }

    int main()
    {
    fork_1();
    return 0;
    }