Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. #include <unistd.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <sys/wait.h>
  5. #include <sys/stat.h>
  6. #include <AK/Assertions.h>
  7. #include <signal.h>
  8. #include <string.h>
  9.  
  10. int main()
  11. {
  12. struct sigaction act;
  13. memset(&act, 0, sizeof(act));
  14. act.sa_flags = SA_NOCLDWAIT;
  15. act.sa_handler = SIG_IGN;
  16. int rc = sigaction(SIGCHLD, &act, nullptr);
  17. if (rc < 0) {
  18. perror("sigaction");
  19. return 1;
  20. }
  21. const char* src = "/bin/rmdir";
  22. const char* dest = "/home/anon/";
  23. printf("Pasting '%s' to '%s'\n", src, dest);
  24.  
  25. pid_t pid = fork();
  26. if (!pid) {
  27. printf("Child: %d\n", pid);
  28. int rc = execl("/bin/cp", "/bin/cp", "-r", src, dest, nullptr);
  29. if (rc < 0) // TODO: show error box
  30. perror("execl");
  31. ASSERT_NOT_REACHED();
  32. } else {
  33. printf("Parent: %d\n", pid);
  34. int wstate = 0;
  35. int res = waitpid(pid, &wstate, 0);
  36. printf("valu: %d, wstate: %d\n", res, wstate);
  37. }
  38.  
  39.  
  40. return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement