Hi friends.I have to write a program which accepts one command line argument,executes the arguments as shell command,determines the time taken by it and prints the time values.I have written a program but it is showing some errors so please tell me where i have gone wrong.
#include<time.h>
#include<sys/times.h>
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
int main(int argc,char *argv[])
{
int i;
struct tms,start,end;
clock_t t1,t2;
staticlong clk_tck;
if(argc<2)
{
printf("Enter the parameter list\n");
exit(0);
}
clktck=sysconf(_SC_CLK_TCK);
start=times(&t1);
system(argv[1]);
end=times(&t2);
printf("Start Time:%f\n",start);
printf("End Time :%f\n",end);
printf("Diffrence:%f\n",((t2.tms_utime-t1.tms_utime)/clktck));
}
Errors
Line18 & 20:Passing argument 1 of times() from incompatible pointer type
Line23:Request for member tms_utime in something not a structure or union
Now if i use a command like cal it gets executed too quickly.So all the values are 0.00.Can u tell me a command which takes a bit more time to execute so that i can see the readings
./a.out cal
<cal output>
start:0.00000
end:0.000000
difference:0.0000
the file has .sh extension....it does not work if i keep or remove the extension
Output
./a.out /home/<username>/1.sh
sh: ./home/<username>/1.sh: No such file
peter i made a mistake by not putting a dot before root.Now it locates but it says permission denied.Plz tell me how to setup execute permisiion for that file.I know we have to use chmod but i don't know the parameters.