/* ** (c) 2003-2006 Herbert Poetzl ** ** V0.1 basic cpu hogging ** V0.2 multi threaded ** */ #include #include #include #include #include #define VERSION "V0.1" static int number = 0; static int seconds = 0; static char *cmd_name = NULL; /* do some CPU hogging */ void *do_hog(void *arg) { int i; unsigned long long v1,v2,v3; while (1) { v1 = 42; v2 = v3 = -1; for (i=0; i<1000; i++) { v1 += i; v2 = v1*i + v3; v3 = v1 ^ v2; } } } #define OPTIONS "hn:s:" int main(int argc, char *argv[]) { extern int optind; extern char *optarg; pthread_t *threads; pthread_attr_t pthread_custom_attr; int i,c,errflg = 0; cmd_name = argv[0]; while ((c = getopt(argc, argv, OPTIONS)) != EOF) { switch (c) { case 'h': fprintf(stderr, "This is %s " VERSION "\n" "options are:\n" "-h print this help message\n" "-n number of threads\n" "-s seconds to sleep\n" ,cmd_name); exit(0); break; case 'n': number = atol(optarg); break; case 's': seconds = atol(optarg); break; case '?': default: errflg++; break; } } if (errflg) { fprintf(stderr, "Usage: %s -" OPTIONS "\n" "%s -h for help.\n", cmd_name, cmd_name); exit(2); } threads=(pthread_t *)malloc(number * sizeof(*threads)); pthread_attr_init(&pthread_custom_attr); for (i=0; i