Created
October 27, 2015 21:03
-
-
Save dacamp/7d8e555b69e288c1243e to your computer and use it in GitHub Desktop.
generate x amount of artificial load
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
#define _BSD_SOURCE /* See feature_test_macros(7) */ | |
#include<unistd.h> | |
#include<stdio.h> | |
#include<stdlib.h> | |
#include<sys/prctl.h> | |
#include <signal.h> | |
int main (int argc, char** argv) { | |
prctl(PR_SET_PDEATHSIG, SIGHUP); | |
int load = atoi(argv[1]); | |
double loadavg[3]; | |
int avg; | |
int oneMin; | |
for (int i = 0; i < load; i++) { | |
avg = getloadavg(loadavg, 1); | |
oneMin = (int) loadavg[0]; | |
if (avg == -1) { | |
return 0; | |
} else if (oneMin < load) | |
if (load%4==1) { | |
if (fork () > 0) { | |
continue; | |
} | |
} | |
while (1) ; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment