Skip to content

Instantly share code, notes, and snippets.

@fclairamb
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fclairamb/c2436397f7517b22be4b to your computer and use it in GitHub Desktop.
Save fclairamb/c2436397f7517b22be4b to your computer and use it in GitHub Desktop.
Change OOM priority score
#ifdef SHELL
gcc -Wall -Werror $0 && ./a.out
exit $?
#endif
#include <stdio.h>
void change_oom_score(int oom_adj) {
FILE * fp = fopen("/proc/self/oom_adj", "w"); // Old one (SK20)
if ( ! fp ) fp = fopen("/proc/self/oom_score_adj", "w"); // New one
if ( fp ) {
fprintf(fp, "%d", oom_adj);
fclose( fp );
}
}
int main() {
change_oom_score( 3 ); // It's already really high
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment