17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 77c478bd9Sstevel@tonic-gate * with the License. 87c478bd9Sstevel@tonic-gate * 97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate * and limitations under the License. 137c478bd9Sstevel@tonic-gate * 147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate * 207c478bd9Sstevel@tonic-gate * CDDL HEADER END 217c478bd9Sstevel@tonic-gate */ 227c478bd9Sstevel@tonic-gate 237c478bd9Sstevel@tonic-gate /* 24*032624d5Sbasabi * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 25*032624d5Sbasabi * Use is subject to license terms. 267c478bd9Sstevel@tonic-gate */ 277c478bd9Sstevel@tonic-gate 28*032624d5Sbasabi #pragma ident "%Z%%M% %I% %E% SMI" 29*032624d5Sbasabi 307c478bd9Sstevel@tonic-gate /* 317c478bd9Sstevel@tonic-gate * rusage 327c478bd9Sstevel@tonic-gate */ 337c478bd9Sstevel@tonic-gate 347c478bd9Sstevel@tonic-gate #include <locale.h> 357c478bd9Sstevel@tonic-gate #include <stdio.h> 367c478bd9Sstevel@tonic-gate #include <sys/types.h> 377c478bd9Sstevel@tonic-gate #include <sys/time.h> 387c478bd9Sstevel@tonic-gate #include <sys/resource.h> 397c478bd9Sstevel@tonic-gate #include <sys/wait.h> 407c478bd9Sstevel@tonic-gate #include <signal.h> 417c478bd9Sstevel@tonic-gate 427c478bd9Sstevel@tonic-gate void 437c478bd9Sstevel@tonic-gate fprintt(s, tv) 447c478bd9Sstevel@tonic-gate char *s; 457c478bd9Sstevel@tonic-gate struct timeval *tv; 467c478bd9Sstevel@tonic-gate { 477c478bd9Sstevel@tonic-gate 487c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("%d.%02d %s "), 497c478bd9Sstevel@tonic-gate tv->tv_sec, tv->tv_usec/10000, s); 507c478bd9Sstevel@tonic-gate } 517c478bd9Sstevel@tonic-gate 52*032624d5Sbasabi int 53*032624d5Sbasabi main(int argc, char **argv) 547c478bd9Sstevel@tonic-gate { 557c478bd9Sstevel@tonic-gate union wait status; 567c478bd9Sstevel@tonic-gate int options = 0; 57*032624d5Sbasabi int p; 587c478bd9Sstevel@tonic-gate struct timeval before, after; 597c478bd9Sstevel@tonic-gate struct rusage ru; 607c478bd9Sstevel@tonic-gate struct timezone tz; 617c478bd9Sstevel@tonic-gate 627c478bd9Sstevel@tonic-gate (void) setlocale(LC_ALL, ""); 637c478bd9Sstevel@tonic-gate 647c478bd9Sstevel@tonic-gate #if !defined(TEXT_DOMAIN) 657c478bd9Sstevel@tonic-gate #define TEXT_DOMAIN "SYS_TEST" 667c478bd9Sstevel@tonic-gate #endif 677c478bd9Sstevel@tonic-gate (void) textdomain(TEXT_DOMAIN); 687c478bd9Sstevel@tonic-gate 697c478bd9Sstevel@tonic-gate if (argc <= 1) 707c478bd9Sstevel@tonic-gate exit(0); 717c478bd9Sstevel@tonic-gate (void) gettimeofday(&before, &tz); 727c478bd9Sstevel@tonic-gate 737c478bd9Sstevel@tonic-gate /* fork a child process to run the command */ 747c478bd9Sstevel@tonic-gate 757c478bd9Sstevel@tonic-gate p = fork(); 767c478bd9Sstevel@tonic-gate if (p < 0) { 777c478bd9Sstevel@tonic-gate perror("rusage"); 787c478bd9Sstevel@tonic-gate exit(1); 797c478bd9Sstevel@tonic-gate } 807c478bd9Sstevel@tonic-gate 817c478bd9Sstevel@tonic-gate if (p == 0) { 827c478bd9Sstevel@tonic-gate 837c478bd9Sstevel@tonic-gate /* exec the command specified */ 847c478bd9Sstevel@tonic-gate 857c478bd9Sstevel@tonic-gate execvp(argv[1], &argv[1]); 867c478bd9Sstevel@tonic-gate perror(argv[1]); 877c478bd9Sstevel@tonic-gate exit(1); 887c478bd9Sstevel@tonic-gate } 897c478bd9Sstevel@tonic-gate 907c478bd9Sstevel@tonic-gate /* parent code - wait for command to complete */ 917c478bd9Sstevel@tonic-gate 927c478bd9Sstevel@tonic-gate (void) signal(SIGINT, SIG_IGN); 937c478bd9Sstevel@tonic-gate (void) signal(SIGQUIT, SIG_IGN); 947c478bd9Sstevel@tonic-gate while (wait3(&status.w_status, options, &ru) != p) 957c478bd9Sstevel@tonic-gate ; 967c478bd9Sstevel@tonic-gate 977c478bd9Sstevel@tonic-gate /* get closing time of day */ 987c478bd9Sstevel@tonic-gate (void) gettimeofday(&after, &tz); 997c478bd9Sstevel@tonic-gate 1007c478bd9Sstevel@tonic-gate /* check for exit status of command */ 1017c478bd9Sstevel@tonic-gate 1027c478bd9Sstevel@tonic-gate if ((status.w_termsig) != 0) 103*032624d5Sbasabi (void) fprintf(stderr, 104*032624d5Sbasabi gettext("Command terminated abnormally.\n")); 1057c478bd9Sstevel@tonic-gate 1067c478bd9Sstevel@tonic-gate /* print an accounting summary line */ 1077c478bd9Sstevel@tonic-gate 1087c478bd9Sstevel@tonic-gate after.tv_sec -= before.tv_sec; 1097c478bd9Sstevel@tonic-gate after.tv_usec -= before.tv_usec; 1107c478bd9Sstevel@tonic-gate if (after.tv_usec < 0) { 1117c478bd9Sstevel@tonic-gate after.tv_sec--; 1127c478bd9Sstevel@tonic-gate after.tv_usec += 1000000; 1137c478bd9Sstevel@tonic-gate } 1147c478bd9Sstevel@tonic-gate fprintt(gettext("real"), &after); 1157c478bd9Sstevel@tonic-gate fprintt(gettext("user"), &ru.ru_utime); 1167c478bd9Sstevel@tonic-gate fprintt(gettext("sys"), &ru.ru_stime); 1177c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("%d pf %d pr %d sw"), 1187c478bd9Sstevel@tonic-gate ru.ru_majflt, 1197c478bd9Sstevel@tonic-gate ru.ru_minflt, 1207c478bd9Sstevel@tonic-gate ru.ru_nswap); 1217c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(" %d rb %d wb %d vcx %d icx"), 1227c478bd9Sstevel@tonic-gate ru.ru_inblock, 1237c478bd9Sstevel@tonic-gate ru.ru_oublock, 1247c478bd9Sstevel@tonic-gate ru.ru_nvcsw, 1257c478bd9Sstevel@tonic-gate ru.ru_nivcsw); 1267c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(" %d mx %d ix %d id %d is"), 1277c478bd9Sstevel@tonic-gate ru.ru_maxrss, 1287c478bd9Sstevel@tonic-gate ru.ru_ixrss, 1297c478bd9Sstevel@tonic-gate ru.ru_idrss, 1307c478bd9Sstevel@tonic-gate ru.ru_isrss); 1317c478bd9Sstevel@tonic-gate 1327c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "\n"); 133*032624d5Sbasabi return ((int)status.w_retcode); 1347c478bd9Sstevel@tonic-gate } 135