Advertisement
Guest User

Untitled

a guest
Dec 13th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <sys/time.h>
  5. #include <sys/resource.h>
  6. #include <sys/types.h>
  7. #include <sys/wait.h>
  8. #include <string.h>
  9. #include <errno.h>
  10.  
  11. int main (int argc, char *const argv[], char *const envp[])
  12. {
  13.  
  14. struct rusage stat;
  15. pid_t is_parent;
  16.  
  17.  
  18.  
  19. int iteration = strtol(argv[1],NULL,0);
  20.  
  21. char * commande = argv[2];
  22.  
  23.  
  24.  
  25.  
  26. for (int i = 0 ; i < iteration ; i++){
  27. system(commande);
  28. }
  29.  
  30. if (getrusage(RUSAGE_CHILDREN, &stat) == -1){
  31. fprintf(stderr, "pb ressources : %s\n", strerror(errno));
  32. exit(4);
  33. }
  34.  
  35. printf("user CPU time : %ld:%.5ld seconds \n", stat.ru_utime.tv_sec/iteration, stat.ru_utime.tv_usec/iteration);
  36. printf("system CPU time : %ld:%.5ld seconds \n", stat.ru_stime.tv_sec/iteration, stat.ru_stime.tv_usec/iteration);
  37.  
  38. exit(0);
  39.  
  40.  
  41. }
  42. pute
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement