Advertisement
Guest User

Untitled

a guest
Feb 21st, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #include <sys/wait.h>
  4.  
  5. int main(int argc, char *argv[])
  6. {
  7. pid_t p, p_wait;
  8. int status;
  9. char *cmd[] = {"/bin/ls", "-l", ".", 0};
  10.  
  11. // fork
  12. if ((p = fork()) > 0) {
  13. // parent
  14. p_wait = wait(&status);
  15. printf("%s [%d] exited with %d\n", cmd[0], p_wait, status);
  16. } else {
  17. // child process
  18. // execve
  19. execve(cmd[0], cmd, 0);
  20. }
  21.  
  22. return 0;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement