Guest User

Untitled

a guest
Apr 21st, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. #include <sched.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <sys/time.h>
  5. #include <sys/resource.h>
  6.  
  7.  
  8.  
  9. void work(int i)
  10. {
  11. //getusage
  12. int who= RUSAGE_SELF;
  13. struct rusage usage;
  14. struct rusage *p=&usage;
  15. //==getrusage
  16. int j;
  17. for(j=0;j<10000;j++)
  18. {
  19.  
  20. }
  21. getrusage(who,p);
  22. printf("N = %d => %d \n",i,p->ru_stime.tv_usec*1000);
  23.  
  24. }
  25.  
  26. main(){
  27.  
  28.  
  29. //time
  30. struct timeval now;
  31. int rc;
  32. //==time
  33.  
  34. struct sched_param param;
  35. int children[100];
  36. int i,j;
  37. int n= 100;
  38.  
  39. param.sched_priority=10;
  40. sched_setscheduler(getpid(),SCHED_RR, &param);
  41.  
  42. for(i=0;i<n;i++)
  43. {
  44.  
  45. if(fork() == 0)
  46. {
  47. param.sched_priority=5;
  48. sched_setscheduler(getpid(),SCHED_RR, &param);
  49. work(i);
  50. return;
  51. }
  52.  
  53.  
  54. }
  55.  
  56. //get time
  57. gettimeofday(&now, NULL);
  58. unsigned a= now.tv_usec;
  59. printf("time = %u.%06u\n",now.tv_sec, now.tv_usec);
  60.  
  61. param.sched_priority=4;
  62. sched_setscheduler(getpid(),SCHED_RR, &param);
  63.  
  64.  
  65. //get time
  66. gettimeofday(&now, NULL);
  67. unsigned b = now.tv_usec;
  68. printf("time = %u.%06u\n",now.tv_sec, now.tv_usec);
  69.  
  70. printf("Diff = 0.%u \n",b-a);
  71.  
  72. }
Add Comment
Please, Sign In to add comment