8867 add MAC_CAPAB_TRANSCEIVER support for cxgbe
[unleashed.git] / usr / src / ucbcmd / rusage / rusage.c
blobe1bfe73aaceba8f2cc502de069ae65bd66d7361c
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
20 * CDDL HEADER END
24 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
25 * Use is subject to license terms.
28 #pragma ident "%Z%%M% %I% %E% SMI"
31 * rusage
34 #include <locale.h>
35 #include <stdio.h>
36 #include <sys/types.h>
37 #include <sys/time.h>
38 #include <sys/resource.h>
39 #include <sys/wait.h>
40 #include <signal.h>
42 void
43 fprintt(s, tv)
44 char *s;
45 struct timeval *tv;
48 (void) fprintf(stderr, gettext("%d.%02d %s "),
49 tv->tv_sec, tv->tv_usec/10000, s);
52 int
53 main(int argc, char **argv)
55 union wait status;
56 int options = 0;
57 int p;
58 struct timeval before, after;
59 struct rusage ru;
60 struct timezone tz;
62 (void) setlocale(LC_ALL, "");
64 #if !defined(TEXT_DOMAIN)
65 #define TEXT_DOMAIN "SYS_TEST"
66 #endif
67 (void) textdomain(TEXT_DOMAIN);
69 if (argc <= 1)
70 exit(0);
71 (void) gettimeofday(&before, &tz);
73 /* fork a child process to run the command */
75 p = fork();
76 if (p < 0) {
77 perror("rusage");
78 exit(1);
81 if (p == 0) {
83 /* exec the command specified */
85 execvp(argv[1], &argv[1]);
86 perror(argv[1]);
87 exit(1);
90 /* parent code - wait for command to complete */
92 (void) signal(SIGINT, SIG_IGN);
93 (void) signal(SIGQUIT, SIG_IGN);
94 while (wait3(&status.w_status, options, &ru) != p)
97 /* get closing time of day */
98 (void) gettimeofday(&after, &tz);
100 /* check for exit status of command */
102 if ((status.w_termsig) != 0)
103 (void) fprintf(stderr,
104 gettext("Command terminated abnormally.\n"));
106 /* print an accounting summary line */
108 after.tv_sec -= before.tv_sec;
109 after.tv_usec -= before.tv_usec;
110 if (after.tv_usec < 0) {
111 after.tv_sec--;
112 after.tv_usec += 1000000;
114 fprintt(gettext("real"), &after);
115 fprintt(gettext("user"), &ru.ru_utime);
116 fprintt(gettext("sys"), &ru.ru_stime);
117 (void) fprintf(stderr, gettext("%d pf %d pr %d sw"),
118 ru.ru_majflt,
119 ru.ru_minflt,
120 ru.ru_nswap);
121 (void) fprintf(stderr, gettext(" %d rb %d wb %d vcx %d icx"),
122 ru.ru_inblock,
123 ru.ru_oublock,
124 ru.ru_nvcsw,
125 ru.ru_nivcsw);
126 (void) fprintf(stderr, gettext(" %d mx %d ix %d id %d is"),
127 ru.ru_maxrss,
128 ru.ru_ixrss,
129 ru.ru_idrss,
130 ru.ru_isrss);
132 (void) fprintf(stderr, "\n");
133 return ((int)status.w_retcode);