fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <sys/types.h>
  4. int main(void){
  5. pid_t pid;
  6. execlp("/bin/ls","ls","-al",NULL);
  7. pid =fork();
  8. if(pid==0){
  9. printf("Child pid: %d\n", pid);
  10. pid =fork();
  11. if(pid==0){
  12. printf("Child pid: %d\n", pid);
  13. }
  14. }
  15. return 0;
  16. }
  17.  
Success #stdin #stdout 0.01s 5556KB
stdin
Standard input is empty
stdout
total 24
drwxr-x--- 2 root 1000  4096 Jun 21 20:08 .
drwxr-xr-x 4 root root  4096 Jun 21 20:08 ..
-rwxr-xr-x 1 root root 14312 Jun 21 20:08 prog