Created
November 26, 2012 13:21
-
-
Save mansr/4148165 to your computer and use it in GitHub Desktop.
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 <stdio.h> | |
#include <unistd.h> | |
#include <sys/types.h> | |
#include <sys/resource.h> | |
#include <sys/wait.h> | |
int main(int argc, char **argv) | |
{ | |
struct rusage ru; | |
pid_t p; | |
int err; | |
if (argc < 2) | |
return 1; | |
p = fork(); | |
if (p < 0) { | |
perror("fork"); | |
return 1; | |
} | |
if (!p) { | |
execvp(argv[1], argv + 1); | |
perror(argv[1]); | |
_exit(127); | |
} | |
waitpid(p, &err, 0); | |
getrusage(RUSAGE_CHILDREN, &ru); | |
fprintf(stderr, "maxrss %ld\n", ru.ru_maxrss); | |
return WEXITSTATUS(err); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment