Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.00 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #include <math.h>
  4. #include <time.h>
  5. #include <sys/time.h>
  6.  
  7. void obciaz(int new_nice) {
  8. nice(new_nice);
  9. int a;
  10. for(int i=0; i<1000000000; i++) {
  11. a = i*i*i*i;
  12. sin(13.254f);
  13. }
  14. }
  15.  
  16. int main(int argc, char **argv) {
  17. for(int i=1; i<argc; i++) {
  18. int new_nice = atoi(argv[i]);
  19. int pid;
  20. if((pid = fork()) == 0) {
  21. struct timeval tv1, tv2;
  22. gettimeofday(&tv1, NULL);
  23. obciaz(new_nice);
  24.  
  25. gettimeofday(&tv2, NULL);
  26. printf("Total time for process of nice %d = %f seconds\n", new_nice,
  27. (double) (tv2.tv_usec - tv1.tv_usec) / 1000000 +
  28. (double) (tv2.tv_sec - tv1.tv_sec));
  29. exit(0);
  30. }
  31. }
  32.  
  33. int status;
  34. for(int i=1; i<argc; i++) {
  35. wait(&status);
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement