I have to find time taken by another program to run; I am using the following code;
system ("time / .outout> garb"); It is giving very weird output.
#include & lt; Stdio.h & gt; Int main () {long int i; (I = 0; i & lt; 10000000; i ++) for {printf ("Hello World! \ N"); } Printf ("C program \ n"); Return 0; } Output
0.31user 0.10 system 0: 00.41 ended 99% CPU (0avgtext + 0avgdata 1744maxresident) 0inputs + 253912outputs (0major + 149minor) Pagefaults 0swaps
One way is wait3 or Waiting 4 functions (if available in your system). pid_t wait3 (int * status, int option, straight rusage * rusage); Pid_t wait4 (pid_t pid, int * status, int option, straight rusage * rusage); After the child is out, your program will get the resource usage of the hair process. Not all fields of
struct rusage are updated, but the first two fields tell you what you want: struct rusage { Struct timeval ru_utime; / * User CPU time used * / straight time = ru_stime; The total CPU time used by the child is / * System CPU time * / ... The sum of ru_utime and ru_stime The code> system () function is not very easy to call. Edit: You can change the time : 0.31user 0.10system
Comments
Post a Comment