fork download
  1. #include<stdio.h>
  2. #include<sys/types.h>
  3. #include<unistd.h>
  4. int main(){
  5. pid_t pid,mypid,myppid;
  6. pid=getpid();
  7. printf(" before fork processs id is%d\n",pid);
  8. pid = fork();
  9. if(pid<0){
  10. mypid=getpid();
  11. myppid=getppid();
  12. printf("process id is%d and ppid is%d\n",mypid,myppid);
  13. }
  14. else{
  15. sleep(2);
  16. printf("this is parrent process \n");
  17. mypid=getpid();
  18. myppid = getppid();
  19. printf("process id sis%d and ppid is%d \n",mypid,myppid);
  20. printf("new created process id or child id is %d \n ",pid);
  21. }
  22. return 0;
  23. }
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
 before fork processs id is2486151
this is parrent process 
process id sis2486151 and ppid is2486150 
new created process id or child id is 2486156 
  before fork processs id is2486151
this is parrent process 
process id sis2486156 and ppid is2486151 
new created process id or child id is 0