fork download
  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #include <sys/types.h>
  4. #include <sys/wait.h>
  5. #include <stdlib.h>
  6.  
  7. int main()
  8. {
  9. pid_t pid;
  10. pid = fork();
  11.  
  12. if (pid < 0)
  13. {
  14. printf("Process creation failed\n");
  15. exit(1);
  16. }
  17. else if (pid == 0)
  18. {
  19. printf("Child process starts\n");
  20. execl("/bin/ls", "ls", NULL);
  21. printf("Exec failed\n");
  22. }
  23. else
  24. {
  25. wait(NULL);
  26. printf("Child Terminated\n");
  27. }
  28.  
  29. return 0;
  30. }
  31.  
Success #stdin #stdout 0.01s 5312KB
stdin
Standard input is empty
stdout
prog
Child Terminated