Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <unistd.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <sys/wait.h>
- #include <sys/stat.h>
- #include <AK/Assertions.h>
- #include <signal.h>
- #include <string.h>
- int main()
- {
- struct sigaction act;
- memset(&act, 0, sizeof(act));
- act.sa_flags = SA_NOCLDWAIT;
- act.sa_handler = SIG_IGN;
- int rc = sigaction(SIGCHLD, &act, nullptr);
- if (rc < 0) {
- perror("sigaction");
- return 1;
- }
- const char* src = "/bin/rmdir";
- const char* dest = "/home/anon/";
- printf("Pasting '%s' to '%s'\n", src, dest);
- pid_t pid = fork();
- if (!pid) {
- printf("Child: %d\n", pid);
- int rc = execl("/bin/cp", "/bin/cp", "-r", src, dest, nullptr);
- if (rc < 0) // TODO: show error box
- perror("execl");
- ASSERT_NOT_REACHED();
- } else {
- printf("Parent: %d\n", pid);
- int wstate = 0;
- int res = waitpid(pid, &wstate, 0);
- printf("valu: %d, wstate: %d\n", res, wstate);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement