/* time(1) with a better precision. */ /* $Id$ */ #include #include #include #include #include int main (int argc, char **argv) { struct timeval tv_start, tv_end, tv_total; pid_t child, pid_got; int status; if (gettimeofday (&tv_start, NULL) != 0) { perror ("gettimeofday ()"); exit (EXIT_FAILURE); } child = fork (); switch (child) { case -1: perror ("fork ()"); exit (EXIT_FAILURE); case 0: execvp (argv[1], argv + 1); perror ("execvp ()"); exit (EXIT_FAILURE); default: pid_got = waitpid (child, &status, 0); if (pid_got != child) { perror ("waitpid ()"); exit (EXIT_FAILURE); } if (!WIFEXITED (status)) { fputs ("!WIFEXITED", stderr); exit (EXIT_FAILURE); } break; } if (gettimeofday (&tv_end, NULL) != 0) { perror ("gettimeofday ()"); exit (EXIT_FAILURE); } timersub (&tv_end, &tv_start, &tv_total); printf ("%ld.%06ld\n", tv_total.tv_sec, tv_total.tv_usec); return WEXITSTATUS (status); }