Skip to content
Snippets Groups Projects
Commit d8d0ea90 authored by Ismael Posada Trobo's avatar Ismael Posada Trobo
Browse files

Add thpoff.c file

parent fb9e65fd
No related branches found
No related tags found
No related merge requests found
thpoff.c 0 → 100644
// PUBLIC DOMAIN CODE
//
// A tiny program that disable transparent huge pages on arbitrary processes
// thpoff echo 1 : will run echo 1 with SET_THP_DISABLE true on the process
#include <stdio.h>
#include <sys/prctl.h>
#include <unistd.h>
#include <errno.h>
int main( int argc, char **argv) {
if (argc < 2) {
fprintf(stderr, "ERROR: expecting at least 1 argument!\n");
return -1;
}
prctl(PR_SET_THP_DISABLE, 1, 0, 0, 0);
char* newargv[argc];
int i;
newargv[argc-1] = NULL;
for (i=1; i<argc; i++) {
newargv[i-1] = argv[i];
}
execvp(argv[1], newargv);
if (errno == ENOENT) {
fprintf(stderr, "ERROR: file not found\n");
return -1;
} else if (errno == EACCES) {
fprintf(stderr, "ERROR: can not run file\n");
return -1;
} else if (errno > 0) {
fprintf(stderr, "ERROR: %i errno while attempting to run file\n", errno);
return -1;
}
return 0;
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment