Advertisement
Guest User

tutuuuuuuuuuuuuuuuuuuuuuuuuur

a guest
Dec 13th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. #include <errno.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <sys/types.h>
  6. #include <sys/wait.h>
  7. #include <unistd.h>
  8. #include <sys/time.h>
  9. #include <sys/resource.h>
  10.  
  11. int main (int argc, char *const argv[], char *const envp[])
  12. {
  13. int t = strtol(argv[1],NULL,10);
  14. for (int i = 0; i < t; i++) {
  15. pid_t res = fork();
  16. if (res ==0) {
  17. execvpe(argv[2],argv+2,envp);
  18. }
  19. else if(res>0){
  20. wait(NULL);
  21. }
  22. }
  23. struct rusage stat;
  24. if (getrusage(RUSAGE_CHILDREN,&stat) == -1) {
  25. fprintf(stderr, "Cannot get ressource usage %s\n",strerror(errno) );
  26. exit(EXIT_FAILURE);
  27. }
  28. printf("User Cpu time %ld:%.21d seconds\n",stat.ru_utime.tv_sec/t,(stat.ru_utime.tv_usec/t));
  29. printf("User Cpu time %ld:%.21d seconds\n",stat.ru_stime.tv_sec/t,(stat.ru_stime.tv_usec/t));
  30.  
  31. exit(0);
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement