/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
#pragma ident "%Z%%M% %I% %E% SMI"
#include <time.h>
#include <string.h>
#include <stdio.h>
#include "acctdef.h"
#include <grp.h>
#include <pwd.h>
#include <locale.h>
#include <stdlib.h>
#include <libgen.h>
double cpucut,
extern long timezone;
extern int daylight; /* daylight savings time if set */
long daydiff,
sys,
user,
cpu,
io,
rw,
mem,
int backward,
fileout = 0,
static int eflg = 0,
Eflg = 0,
sflg = 0,
Sflg = 0;
#ifdef uts
#else
#endif
long convtime();
#ifdef uts
float expand();
#else
#endif
char *ofile,
*devtolin(),
*uidtonam();
void dofile(char *);
void doexit(int) __NORETURN;
void usage(void);
void fatal(char *, char *);
void println(void);
void printhd(void);
char *cmset(char *);
int
{
int c;
"C:E:H:I:O:S:abe:fg:hikl:mn:o:qrs:tu:v")) != EOF) {
switch(c) {
case 'C':
continue;
case 'O':
continue;
case 'H':
continue;
case 'I':
continue;
case 'a':
average++;
continue;
case 'b':
backward++;
continue;
case 'g':
else
gidflag++;
continue;
case 'h':
continue;
case 'i':
continue;
case 'k':
continue;
case 'm':
continue;
case 'n':
continue;
case 't':
continue;
case 'r':
continue;
case 'v':
verbose=0;
continue;
case 'l':
continue;
case 'u':
if(*optarg == '?') {
unkid++;
continue;
}
if(*optarg == '#') {
su_user++;
uidval = 0;
uidflag++;
continue;
}
/* atoi will return 0 in abnormal situation */
exit(1);
}
exit(1);
}
uidflag++;
} else {
uidflag++;
}
continue;
case 'q':
quiet++;
verbose=0;
average++;
continue;
case 's':
sflg = 1;
continue;
case 'S':
Sflg = 1;
continue;
case 'f':
flag_field++;
continue;
case 'e':
eflg = 1;
continue;
case 'E':
Eflg = 1;
continue;
case 'o':
fileout++;
perror("open error on output file");
errflg++;
}
continue;
case '?':
errflg++;
continue;
}
}
if(errflg) {
usage();
exit(1);
}
nfiles++;
}
if(nfiles==0) {
else {
stdinflg = 1;
}
}
doexit(0);
/* NOTREACHED */
}
void
{
struct tm *t;
ts_b = 0,
te_a = 0,
te_b = 0;
long daystart;
long nsize;
for daylight savings time */
return;
}
return;
else
if(backward) {
if (ver == 2)
else
}
tzset();
time_t t;
/*
* it is older than today
*/
}
/* adjust time by one hour for daylight savings time */
dst_secs = 3600;
else
dst_secs = 0;
if (Sflg) {
}
if (eflg) {
}
if (sflg) {
}
if (Eflg) {
}
if(ts_a) {
}
if(backward) return;
else continue;
}
if(backward) continue;
else return;
}
continue;
continue;
}
continue;
continue;
if(cpu == 0)
cpu = 1;
continue;
continue;
#ifdef uts
continue;
#else
continue;
#endif
continue;
continue;
continue;
continue;
continue;
printhd();
verbose = 0;
}
if(elapsed == 0)
elapsed++;
continue;
if(fileout)
else
println();
if(average) {
cmdcount++;
};
}
}
int
{
int ret;
if (ver != 2) {
/* copy SVR3 acct struct to SVR4 acct struct */
}
} else
if(backward) {
if(ok) {
sizeof(struct o_acct))), 1) != 0) {
ok = 0;
}
} else
ret = 0;
}
}
void
printhd(void)
{
ps("CPU");
ps("(SECS)");
ps("CHARS");
ps("BLOCKS");
}
ps("CPU");
ps("HOG");
ps("MEAN");
ps("KCORE");
ps("SYS");
ps("USER");
} else
ps("(SECS)");
ps("TRNSFD");
ps("READ");
}
ps("FACTOR");
ps("FACTOR");
ps("SIZE(K)");
ps("MIN");
if(flag_field)
}
void
println(void)
{
time_t t;
if(quiet)
return;
else {
}
if(*name != '?')
else
#ifdef uts
#else
#endif
t = a->ac_btime;
} else
if(flag_field)
(unsigned char) a->ac_stat);
}
/*
* convtime converts time arg to internal value
* arg has form hr:min:sec, min or sec are assumed to be 0 if omitted
*/
long
char *str;
{
}
tzset();
}
int
{
int i;
for(i=0;i<8;i++){
break;
}
xcomm[i] = '\0';
}
char *
{
}
return (pattern);
}
void
{
if(!average)
if(cmdcount) {
}
else
}
int
isdevnull(void)
{
return (0);
}
return (0);
}
return (1);
else
return (0);
}
void
{
exit(1);
}
void
usage(void)
{
diag("-b read backwards through file");
diag("-h print hog factor (total-CPU-time/elapsed-time)");
diag("-i print I/O counts");
diag("-k show total Kcore minutes instead of memory size");
diag("-m show mean memory size");
diag("-r show CPU factor (user-time/(sys-time + user-time))");
diag("-t show separate system and user CPU times");
diag("-v don't print column headings");
diag("-a print average statistics of selected commands");
diag("-q print average statistics only");
diag("-u user \tshow processes belonging to user name or user ID");
diag("-u # \tshow processes executed by super-user");
diag("-u ? \tshow processes executed by unknown UID's");
diag("-g group show processes belonging to group name of group ID");
diag("-s time \tshow processes ending after time (hh[:mm[:ss]])");
diag("-e time \tshow processes starting before time");
diag("-S time \tshow processes starting after time");
diag("-E time \tshow processes ending before time");
diag("-n regex select commands matching the ed(1) regular expression");
diag("-o file \tdo not print, put selected pacct records into file");
diag("-H factor show processes that exceed hog factor");
diag("-O sec \tshow processes that exceed CPU system time sec");
diag("-C sec \tshow processes that exceed total CPU time sec");
diag("-I chars show processes that transfer more than char chars");
}