Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sched.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <sys/time.h>
- #include <sys/resource.h>
- void work(int i)
- {
- //getusage
- int who= RUSAGE_SELF;
- struct rusage usage;
- struct rusage *p=&usage;
- //==getrusage
- int j;
- for(j=0;j<10000;j++)
- {
- }
- getrusage(who,p);
- printf("N = %d => %d \n",i,p->ru_stime.tv_usec*1000);
- }
- main(){
- //time
- struct timeval now;
- int rc;
- //==time
- struct sched_param param;
- int children[100];
- int i,j;
- int n= 100;
- param.sched_priority=10;
- sched_setscheduler(getpid(),SCHED_RR, ¶m);
- for(i=0;i<n;i++)
- {
- if(fork() == 0)
- {
- param.sched_priority=5;
- sched_setscheduler(getpid(),SCHED_RR, ¶m);
- work(i);
- return;
- }
- }
- //get time
- gettimeofday(&now, NULL);
- unsigned a= now.tv_usec;
- printf("time = %u.%06u\n",now.tv_sec, now.tv_usec);
- param.sched_priority=4;
- sched_setscheduler(getpid(),SCHED_RR, ¶m);
- //get time
- gettimeofday(&now, NULL);
- unsigned b = now.tv_usec;
- printf("time = %u.%06u\n",now.tv_sec, now.tv_usec);
- printf("Diff = 0.%u \n",b-a);
- }
Add Comment
Please, Sign In to add comment