* Copyright (c) 1987, 1988 The Regents of the University of California.
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
"@(#) Copyright (c) 1987, 1988 The Regents of the University of California.\n\
static char sccsid
[] = "@(#)time.c 4.8 (Berkeley) %G%";
#include <sys/resource.h>
struct timeval before
, after
;
while ((ch
= getopt(argc
, argv
, "l")) != EOF
)
fprintf(stderr
, "usage: time [-l] command.\n");
gettimeofday(&before
, (struct timezone
*)NULL
);
(void)signal(SIGINT
, SIG_IGN
);
(void)signal(SIGQUIT
, SIG_IGN
);
while (wait3(&status
, 0, &ru
) != pid
); /* XXX use waitpid */
gettimeofday(&after
, (struct timezone
*)NULL
);
fprintf(stderr
, "Command terminated abnormally.\n");
after
.tv_sec
-= before
.tv_sec
;
after
.tv_usec
-= before
.tv_usec
;
after
.tv_sec
--, after
.tv_usec
+= 1000000;
fprintf(stderr
, "%9ld.%02ld real ", after
.tv_sec
, after
.tv_usec
/10000);
fprintf(stderr
, "%9ld.%02ld user ",
ru
.ru_utime
.tv_sec
, ru
.ru_utime
.tv_usec
/10000);
fprintf(stderr
, "%9ld.%02ld sys\n",
ru
.ru_stime
.tv_sec
, ru
.ru_stime
.tv_usec
/10000);
ticks
= hz
* (ru
.ru_utime
.tv_sec
+ ru
.ru_stime
.tv_sec
) +
hz
* (ru
.ru_utime
.tv_usec
+ ru
.ru_stime
.tv_usec
) / 1000000;
fprintf(stderr
, "%10ld %s\n",
ru
.ru_maxrss
, "maximum resident set size");
fprintf(stderr
, "%10ld %s\n",
ru
.ru_ixrss
/ ticks
, "average shared memory size");
fprintf(stderr
, "%10ld %s\n",
ru
.ru_idrss
/ ticks
, "average unshared data size");
fprintf(stderr
, "%10ld %s\n",
ru
.ru_isrss
/ ticks
, "average unshared stack size");
fprintf(stderr
, "%10ld %s\n",
ru
.ru_minflt
, "page reclaims");
fprintf(stderr
, "%10ld %s\n",
ru
.ru_majflt
, "page faults");
fprintf(stderr
, "%10ld %s\n",
fprintf(stderr
, "%10ld %s\n",
ru
.ru_inblock
, "block input operations");
fprintf(stderr
, "%10ld %s\n",
ru
.ru_oublock
, "block output operations");
fprintf(stderr
, "%10ld %s\n",
ru
.ru_msgsnd
, "messages sent");
fprintf(stderr
, "%10ld %s\n",
ru
.ru_msgrcv
, "messages received");
fprintf(stderr
, "%10ld %s\n",
ru
.ru_nsignals
, "signals received");
fprintf(stderr
, "%10ld %s\n",
ru
.ru_nvcsw
, "voluntary context switches");
fprintf(stderr
, "%10ld %s\n",
ru
.ru_nivcsw
, "involuntary context switches");