C实现
#include <math.h>
#include <stdio.h>
#include <sys/time.h>
int main(int argc, int **argv)
{
int i;
struct timeval start;
struct timeval end;
double timeuse;
char *exec_argv[4];
if (argc == 1)
{
printf("Error!\n");
exit(0);
}
if (fork() == 0)
{
for (i = 0; i < argc; i++)
{
exec_argv[i] = argv[i + 1];
printf("[%d]:%s\n", i, exec_argv[i]);
}
printf("Child Create\n");
execv(argv[1], exec_argv);
}
else
{
gettimeofday( & start, NULL);
wait(1000);
gettimeofday( & end, NULL);
timeuse = (1000000 * (end.tv_sec - start.tv_sec) + end.tv_usec - start.tv_usec);
printf("time:%lf ms\n", timeuse);
}
return 0;
}
网友评论