-
-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #149: tests: Add regression test for fork+exec of another binary
- Loading branch information
1 parent
46ff733
commit 5807902
Showing
2 changed files
with
33 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#include <unistd.h> | ||
#include <stdio.h> | ||
#include <sys/ptrace.h> | ||
#include <sys/user.h> | ||
#include <sys/types.h> | ||
#include <sys/wait.h> | ||
#include <sched.h> | ||
|
||
int main(int argc, const char *argv[]) | ||
{ | ||
pid_t child; | ||
int status; | ||
|
||
child = fork(); | ||
if (child < 0) { | ||
fprintf(stderr, "fork failed!\n"); | ||
return -1; | ||
} | ||
|
||
if (child > 0) { | ||
printf("Parent %d\n", getpid()); | ||
} else if (child < 0) { | ||
printf("ERROR!\n"); | ||
} else { | ||
printf("Child, will exec()\n"); | ||
execvp(argv[1], NULL); | ||
} | ||
|
||
waitpid(child, &status, 0); | ||
|
||
return 0; | ||
} |