
Timing a program (process) from another program
Hi!
I need to write a program that start a second program and also time
the execution time for the second program. I did a try (following
code) but of course it did not work properly. I’m very glad if
someone could help me.
/jola
/************************************************/
void process(void){
pid_t pid;
if((pid = fork())<0)
printf("error at 1\n");
else if (pid == 0){
if(execl("/home/xsajlar/Test_Prog/timing/run",
"run",NULL) <0)
printf("error at 2\n");
}
if(waitpid(pid, NULL,0)<0)
printf("error at 3\n");
Quote:
}
main(){
clock_t start, stop, duration;
struct timeval first_time, sec_time;
float tot_time;
gettimeofday(&first_time, NULL);
start = clock();
/**Want to time this part**/
process();
/**************************/
stop = clock();
gettimeofday(&sec_time, NULL);
tot_time = (float)(sec_time.tv_usec - first_time.tv_usec)*1.0e-6;
printf("first_time = %f\n",(float)first_time.tv_usec);
printf("sec_time = %f\n",(float)sec_time.tv_usec);
printf("tot from gettimeofday = %f sec (real time)\n",tot_time);
duration = stop - start;
printf("tot time fom clock = %f sec (user time) \n",
((double) (stop - start)) / CLOCKS_PER_SEC);
exit(0);
return 0;
Quote:
}
/************************************************/