fork download
  1. #include<stdio.h>
  2. #include<unistd.h>
  3. #include<sys/wait.h>
  4. #include<sys/types.h>
  5. #include<stdlib.h>
  6. int main()
  7. {
  8. int pid;
  9. pid=fork();
  10. if(pid<0)
  11. {
  12. printf("\nFORK FAILED\n");
  13. exit(-1);
  14. }
  15. else if(pid==0)
  16. {
  17. execlp("/bin/ls","is","-1",NULL);
  18. }
  19. else
  20. {
  21. wait(NULL);
  22. printf("\nCHILD COMPLETE\n");
  23. exit(0);
  24. }
  25. }
Success #stdin #stdout 0.01s 5292KB
stdin
Standard input is empty
stdout
prog

CHILD COMPLETE