fork download
  1. #include<stdio.h>
  2. #include<sys/types.h>
  3. #include<unistd.h>
  4. #include<sys/wait.h>
  5. int main(){
  6. pid_t pid;
  7. pid=fork();
  8. if(pid<0){
  9. printf("fork() function failed");
  10. return 1;
  11. }
  12. else if(pid==0){
  13. printf("Child pid: %d\n", getpid());
  14. printf("Child ppid: %d\n", getppid());
  15. }
  16. else{
  17. printf("Parent pid: %d\n", getpid());
  18. printf("Parent ppid: %d\n", getppid());
  19. wait(NULL);
  20. }
  21. return 0;
  22. }
Success #stdin #stdout 0.01s 5272KB
stdin
Standard input is empty
stdout
Child pid: 934648
Child ppid: 934643
Parent pid: 934643
Parent ppid: 934604