Skip to content

Instantly share code, notes, and snippets.

@mansr
Created November 26, 2012 13:21
Show Gist options
  • Save mansr/4148165 to your computer and use it in GitHub Desktop.
Save mansr/4148165 to your computer and use it in GitHub Desktop.
#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