Created
March 19, 2014 22:47
-
-
Save zhuowei/9653033 to your computer and use it in GitHub Desktop.
Use brute force and ignorance to run a program with a specified PID
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <unistd.h> | |
#include <stdlib.h> | |
int main(int argc, char** argv) { | |
int targetPid = atoi(argv[1]); | |
for(;;) { | |
int newPid = fork(); | |
if (newPid == 0) { //child | |
newPid = getpid(); | |
if (newPid == targetPid) { | |
execv(argv[2], argv + 3); | |
} else { | |
exit(0); | |
} | |
} else { | |
if (newPid == targetPid) { | |
exit(0); | |
} else { | |
wait(NULL); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment