Skip to content

Instantly share code, notes, and snippets.

@shihyu
Created November 24, 2018 15:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shihyu/10f7021b4a0f277b1cf9d045a8d41e86 to your computer and use it in GitHub Desktop.
Save shihyu/10f7021b4a0f277b1cf9d045a8d41e86 to your computer and use it in GitHub Desktop.
#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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment