Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <errno.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <sys/types.h>
- #include <sys/wait.h>
- #include <unistd.h>
- #include <sys/time.h>
- #include <sys/resource.h>
- int main (int argc, char *const argv[], char *const envp[])
- {
- int t = strtol(argv[1],NULL,10);
- for (int i = 0; i < t; i++) {
- pid_t res = fork();
- if (res ==0) {
- execvpe(argv[2],argv+2,envp);
- }
- else if(res>0){
- wait(NULL);
- }
- }
- // struct rusage stat;
- // if (getrusage(RUSAGE_CHILDREN,&stat) == -1) {
- // fprintf(stderr, "Cannot get ressource usage %s\n",strerror(errno) );
- // exit(EXIT_FAILURE);
- // }
- // printf("User Cpu time %ld:%.21d seconds\n",stat.ru_utime.tv_sec/iter,(stat.ru_utime.tv_usec/iter));
- // printf("User Cpu time %ld:%.21d seconds\n",stat.ru_stime.tv_sec/iter,(stat.ru_stime.tv_usec/iter));
- exit(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement