Skip to content

Instantly share code, notes, and snippets.

@MinusGix
Created September 8, 2019 11:02
Show Gist options
  • Save MinusGix/c6355f9ee2f0712d3633d6ac0a316452 to your computer and use it in GitHub Desktop.
Save MinusGix/c6355f9ee2f0712d3633d6ac0a316452 to your computer and use it in GitHub Desktop.
#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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment