fork download
  1. #include<stdio.h>
  2. #include<unistd.h>
  3. main()
  4. {
  5. int signal;
  6. int pid;
  7. printf("\nhi i am parent process i am going to create a child\n");
  8. pid=fork();
  9. if(pid==0)
  10. {
  11. printf("\nhi i am child process. i am going to jump to a different parent process\n");
  12. execl("/bin/ls","ls","-l",NULL);
  13. }
  14. else if(pid>0)
  15. {
  16. printf("\nhi i am parent. i will wait for my child to complete\n");
  17. wait(&signal);
  18. printf("\ni got signal=%d so my child jumped to another process. i am exiting\n",signal);
  19. }
  20. }
Success #stdin #stdout 0.01s 5280KB
stdin
Standard input is empty
stdout
total 16
-rwxr-xr-x 1 root root 14312 Oct 29 17:42 prog

hi i am parent process i am going to create a child

hi i am parent. i will wait for my child to complete

i got signal=0 so my child jumped to another process. i am exiting