linux - Create a C program to load the CPU utilization >70% but lower than 80% -


i creating test program test cpu performance , temperature while cpu usage between 70% 80%. using threads run calculation in loop , non-stop. cpus increase 100%. have no clue on maintaining usage not higher 80%, higher 70%. can have advice?

void *docalculate(void *a);  int main(void) {     pthread_t threads[num_thread];     int thread_args[num_thread];     int i,s;    //create threads    (i=0; i<num_thread; ++i)    {         thread_args[i] = i;         printf("spawning thread %d\n", i);         s=pthread_create(&threads[i], null, docalculate, (void *)      &thread_args[i]);         if(s!=0)         handle_error(s,"pthread_create");    }    //wait threads finish    (i=0; i<num_thread; ++i) {        pthread_join(threads[i], null);   }   return 1; }  void *docalculate(void *a){     int tid;     tid = *((int *) a);     printf("thread %d!\n", tid);     float x = 1.5f;     while (1)     {         x *= sin(x) / atan(x) * tanh(x) ;      } } 

here temporary solution. put printf , loop in function docalculation.

void *docalculate(void *a){     int tid;     tid = *((int *) a);     printf("thread %d!\n", tid);     float x = 1.5f;     while (1)     {            int i=0;         printf("\t\n\n");         x *= sin(x) / atan(x) * tanh(x) ;         for(;i<15000;i++){}     } } 

you send sigstop , sigcont signals (see signal(7)...) process group. you'll use /proc/ (see proc(5)) measure load.

my half.c program (self contained, on github) inspirational. runs command @ half-speed (by stop-ing frequently, e.g. every tenth of second, , later cont-inuing , repeating again).

(i wrote around 2005 overcome hardware deficiency - bad overheating ram modules - on turion msi-270 laptop; able half make linux kernel, while plain make crashed panic laptop because of overheating).

read advanced linux programming

search around cpu affinity. see taskset(1), sched_setaffinity(2),


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -