Make ps(1) automatically size its column widths.
This commit is contained in:
parent
762f55cd5f
commit
1d1143ec27
@ -39,63 +39,52 @@ extern fixpt_t ccpu;
|
||||
extern int cflag, eval, fscale, nlistread, rawcpu;
|
||||
extern unsigned long mempages;
|
||||
extern time_t now;
|
||||
extern int showthreads, sumrusage, termwidth, totwidth;
|
||||
extern int showthreads, sumrusage, termwidth;
|
||||
extern STAILQ_HEAD(velisthead, varent) varlist;
|
||||
|
||||
__BEGIN_DECLS
|
||||
void arguments(KINFO *, VARENT *);
|
||||
void command(KINFO *, VARENT *);
|
||||
void cputime(KINFO *, VARENT *);
|
||||
char *arguments(KINFO *, VARENT *);
|
||||
char *command(KINFO *, VARENT *);
|
||||
char *cputime(KINFO *, VARENT *);
|
||||
int donlist(void);
|
||||
void elapsed(KINFO *, VARENT *);
|
||||
void elapseds(KINFO *, VARENT *);
|
||||
void emulname(KINFO *, VARENT *);
|
||||
char *elapsed(KINFO *, VARENT *);
|
||||
char *elapseds(KINFO *, VARENT *);
|
||||
char *emulname(KINFO *, VARENT *);
|
||||
VARENT *find_varentry(VAR *);
|
||||
const char *fmt_argv(char **, char *, size_t);
|
||||
double getpcpu(const KINFO *);
|
||||
void kvar(KINFO *, VARENT *);
|
||||
void label(KINFO *, VARENT *);
|
||||
void loginclass(KINFO *, VARENT *);
|
||||
void logname(KINFO *, VARENT *);
|
||||
void longtname(KINFO *, VARENT *);
|
||||
void lstarted(KINFO *, VARENT *);
|
||||
void maxrss(KINFO *, VARENT *);
|
||||
void lockname(KINFO *, VARENT *);
|
||||
void mwchan(KINFO *, VARENT *);
|
||||
void nwchan(KINFO *, VARENT *);
|
||||
void pagein(KINFO *, VARENT *);
|
||||
char *kvar(KINFO *, VARENT *);
|
||||
char *label(KINFO *, VARENT *);
|
||||
char *loginclass(KINFO *, VARENT *);
|
||||
char *logname(KINFO *, VARENT *);
|
||||
char *longtname(KINFO *, VARENT *);
|
||||
char *lstarted(KINFO *, VARENT *);
|
||||
char *maxrss(KINFO *, VARENT *);
|
||||
char *lockname(KINFO *, VARENT *);
|
||||
char *mwchan(KINFO *, VARENT *);
|
||||
char *nwchan(KINFO *, VARENT *);
|
||||
char *pagein(KINFO *, VARENT *);
|
||||
void parsefmt(const char *, int);
|
||||
void pcpu(KINFO *, VARENT *);
|
||||
void pmem(KINFO *, VARENT *);
|
||||
void pri(KINFO *, VARENT *);
|
||||
char *pcpu(KINFO *, VARENT *);
|
||||
char *pmem(KINFO *, VARENT *);
|
||||
char *pri(KINFO *, VARENT *);
|
||||
void printheader(void);
|
||||
void priorityr(KINFO *, VARENT *);
|
||||
void egroupname(KINFO *, VARENT *);
|
||||
void rgroupname(KINFO *, VARENT *);
|
||||
void runame(KINFO *, VARENT *);
|
||||
void rvar(KINFO *, VARENT *);
|
||||
int s_comm(KINFO *);
|
||||
int s_cputime(KINFO *);
|
||||
int s_label(KINFO *);
|
||||
int s_loginclass(KINFO *);
|
||||
int s_logname(KINFO *);
|
||||
int s_egroupname(KINFO *);
|
||||
int s_rgroupname(KINFO *);
|
||||
int s_runame(KINFO *);
|
||||
int s_systime(KINFO *);
|
||||
int s_uname(KINFO *);
|
||||
int s_usertime(KINFO *);
|
||||
char *priorityr(KINFO *, VARENT *);
|
||||
char *egroupname(KINFO *, VARENT *);
|
||||
char *rgroupname(KINFO *, VARENT *);
|
||||
char *runame(KINFO *, VARENT *);
|
||||
char *rvar(KINFO *, VARENT *);
|
||||
void showkey(void);
|
||||
void started(KINFO *, VARENT *);
|
||||
void state(KINFO *, VARENT *);
|
||||
void systime(KINFO *, VARENT *);
|
||||
void tdev(KINFO *, VARENT *);
|
||||
void tdnam(KINFO *, VARENT *);
|
||||
void tname(KINFO *, VARENT *);
|
||||
void ucomm(KINFO *, VARENT *);
|
||||
void uname(KINFO *, VARENT *);
|
||||
void upr(KINFO *, VARENT *);
|
||||
void usertime(KINFO *, VARENT *);
|
||||
void vsize(KINFO *, VARENT *);
|
||||
void wchan(KINFO *, VARENT *);
|
||||
char *started(KINFO *, VARENT *);
|
||||
char *state(KINFO *, VARENT *);
|
||||
char *systime(KINFO *, VARENT *);
|
||||
char *tdev(KINFO *, VARENT *);
|
||||
char *tdnam(KINFO *, VARENT *);
|
||||
char *tname(KINFO *, VARENT *);
|
||||
char *ucomm(KINFO *, VARENT *);
|
||||
char *uname(KINFO *, VARENT *);
|
||||
char *upr(KINFO *, VARENT *);
|
||||
char *usertime(KINFO *, VARENT *);
|
||||
char *vsize(KINFO *, VARENT *);
|
||||
char *wchan(KINFO *, VARENT *);
|
||||
__END_DECLS
|
||||
|
262
bin/ps/keyword.c
262
bin/ps/keyword.c
@ -57,178 +57,116 @@ static int vcmp(const void *, const void *);
|
||||
#define KOFF(x) offsetof(struct kinfo_proc, x)
|
||||
#define ROFF(x) offsetof(struct rusage, x)
|
||||
|
||||
#define EMULLEN 13 /* enough for "FreeBSD ELF32" */
|
||||
#define LWPFMT "d"
|
||||
#define LWPLEN 6
|
||||
#define NLWPFMT "d"
|
||||
#define NLWPLEN 4
|
||||
#define UIDFMT "u"
|
||||
#define UIDLEN 5
|
||||
#define PIDFMT "d"
|
||||
#define PIDLEN 5
|
||||
#define USERLEN (MAXLOGNAME - 1)
|
||||
|
||||
/* PLEASE KEEP THE TABLE BELOW SORTED ALPHABETICALLY!!! */
|
||||
static VAR var[] = {
|
||||
{"%cpu", "%CPU", NULL, 0, pcpu, NULL, 5, 0, CHAR, NULL, 0},
|
||||
{"%mem", "%MEM", NULL, 0, pmem, NULL, 4, 0, CHAR, NULL, 0},
|
||||
{"acflag", "ACFLG", NULL, 0, kvar, NULL, 3, KOFF(ki_acflag), USHORT,
|
||||
"x", 0},
|
||||
{"acflg", "", "acflag", 0, NULL, NULL, 0, 0, CHAR, NULL, 0},
|
||||
{"args", "COMMAND", NULL, COMM|LJUST|USER, arguments, NULL, 16, 0,
|
||||
{"%cpu", "%CPU", NULL, 0, pcpu, 0, CHAR, NULL, 0},
|
||||
{"%mem", "%MEM", NULL, 0, pmem, 0, CHAR, NULL, 0},
|
||||
{"acflag", "ACFLG", NULL, 0, kvar, KOFF(ki_acflag), USHORT, "x", 0},
|
||||
{"acflg", "", "acflag", 0, NULL, 0, CHAR, NULL, 0},
|
||||
{"args", "COMMAND", NULL, COMM|LJUST|USER, arguments, 0,
|
||||
CHAR, NULL, 0},
|
||||
{"blocked", "", "sigmask", 0, NULL, NULL, 0, 0, CHAR, NULL, 0},
|
||||
{"caught", "", "sigcatch", 0, NULL, NULL, 0, 0, CHAR, NULL, 0},
|
||||
{"class", "CLASS", NULL, LJUST, loginclass, s_loginclass,
|
||||
MAXLOGNAME-1, 0, CHAR, NULL, 0},
|
||||
{"comm", "COMMAND", NULL, LJUST, ucomm, s_comm,
|
||||
COMMLEN + TDNAMLEN + 1, 0, CHAR, NULL, 0},
|
||||
{"command", "COMMAND", NULL, COMM|LJUST|USER, command, NULL, 16, 0,
|
||||
{"blocked", "", "sigmask", 0, NULL, 0, CHAR, NULL, 0},
|
||||
{"caught", "", "sigcatch", 0, NULL, 0, CHAR, NULL, 0},
|
||||
{"class", "CLASS", NULL, LJUST, loginclass, 0, CHAR, NULL, 0},
|
||||
{"comm", "COMMAND", NULL, LJUST, ucomm, 0, CHAR, NULL, 0},
|
||||
{"command", "COMMAND", NULL, COMM|LJUST|USER, command, 0,
|
||||
CHAR, NULL, 0},
|
||||
{"cpu", "CPU", NULL, 0, kvar, NULL, 3, KOFF(ki_estcpu), UINT, "d",
|
||||
0},
|
||||
{"cputime", "", "time", 0, NULL, NULL, 0, 0, CHAR, NULL, 0},
|
||||
{"egid", "", "gid", 0, NULL, NULL, 0, 0, CHAR, NULL, 0},
|
||||
{"egroup", "", "group", 0, NULL, NULL, 0, 0, CHAR, NULL, 0},
|
||||
{"emul", "EMUL", NULL, LJUST, emulname, NULL, EMULLEN, 0, CHAR,
|
||||
NULL, 0},
|
||||
{"etime", "ELAPSED", NULL, USER, elapsed, NULL, 12, 0, CHAR, NULL, 0},
|
||||
{"etimes", "ELAPSED", NULL, USER, elapseds, NULL, 12, 0, CHAR, NULL, 0},
|
||||
{"euid", "", "uid", 0, NULL, NULL, 0, 0, CHAR, NULL, 0},
|
||||
{"f", "F", NULL, 0, kvar, NULL, 8, KOFF(ki_flag), INT, "x", 0},
|
||||
{"flags", "", "f", 0, NULL, NULL, 0, 0, CHAR, NULL, 0},
|
||||
{"gid", "GID", NULL, 0, kvar, NULL, UIDLEN, KOFF(ki_groups),
|
||||
UINT, UIDFMT, 0},
|
||||
{"group", "GROUP", NULL, LJUST, egroupname, s_egroupname,
|
||||
USERLEN, 0, CHAR, NULL, 0},
|
||||
{"ignored", "", "sigignore", 0, NULL, NULL, 0, 0, CHAR, NULL, 0},
|
||||
{"inblk", "INBLK", NULL, USER, rvar, NULL, 4, ROFF(ru_inblock), LONG,
|
||||
"ld", 0},
|
||||
{"inblock", "", "inblk", 0, NULL, NULL, 0, 0, CHAR, NULL, 0},
|
||||
{"jid", "JID", NULL, 0, kvar, NULL, 6, KOFF(ki_jid), INT, "d", 0},
|
||||
{"jobc", "JOBC", NULL, 0, kvar, NULL, 4, KOFF(ki_jobc), SHORT, "d",
|
||||
0},
|
||||
{"ktrace", "KTRACE", NULL, 0, kvar, NULL, 8, KOFF(ki_traceflag), INT,
|
||||
"x", 0},
|
||||
{"label", "LABEL", NULL, LJUST, label, s_label, SHRT_MAX, 0, CHAR,
|
||||
NULL, 0},
|
||||
{"lim", "LIM", NULL, 0, maxrss, NULL, 5, 0, CHAR, NULL, 0},
|
||||
{"lockname", "LOCK", NULL, LJUST, lockname, NULL, 6, 0, CHAR, NULL,
|
||||
0},
|
||||
{"login", "LOGIN", NULL, LJUST, logname, s_logname, MAXLOGNAME-1,
|
||||
0, CHAR, NULL, 0},
|
||||
{"logname", "", "login", 0, NULL, NULL, 0, 0, CHAR, NULL, 0},
|
||||
{"lstart", "STARTED", NULL, LJUST|USER, lstarted, NULL, 28, 0, CHAR,
|
||||
NULL, 0},
|
||||
{"lwp", "LWP", NULL, 0, kvar, NULL, LWPLEN, KOFF(ki_tid), UINT,
|
||||
LWPFMT, 0},
|
||||
{"majflt", "MAJFLT", NULL, USER, rvar, NULL, 4, ROFF(ru_majflt),
|
||||
LONG, "ld", 0},
|
||||
{"minflt", "MINFLT", NULL, USER, rvar, NULL, 4, ROFF(ru_minflt),
|
||||
LONG, "ld", 0},
|
||||
{"msgrcv", "MSGRCV", NULL, USER, rvar, NULL, 4, ROFF(ru_msgrcv),
|
||||
LONG, "ld", 0},
|
||||
{"msgsnd", "MSGSND", NULL, USER, rvar, NULL, 4, ROFF(ru_msgsnd),
|
||||
LONG, "ld", 0},
|
||||
{"mwchan", "MWCHAN", NULL, LJUST, mwchan, NULL, 6, 0, CHAR, NULL, 0},
|
||||
{"ni", "", "nice", 0, NULL, NULL, 0, 0, CHAR, NULL, 0},
|
||||
{"nice", "NI", NULL, 0, kvar, NULL, 2, KOFF(ki_nice), CHAR, "d",
|
||||
0},
|
||||
{"nivcsw", "NIVCSW", NULL, USER, rvar, NULL, 5, ROFF(ru_nivcsw),
|
||||
LONG, "ld", 0},
|
||||
{"nlwp", "NLWP", NULL, 0, kvar, NULL, NLWPLEN, KOFF(ki_numthreads),
|
||||
UINT, NLWPFMT, 0},
|
||||
{"nsignals", "", "nsigs", 0, NULL, NULL, 0, 0, CHAR, NULL, 0},
|
||||
{"nsigs", "NSIGS", NULL, USER, rvar, NULL, 4, ROFF(ru_nsignals),
|
||||
LONG, "ld", 0},
|
||||
{"nswap", "NSWAP", NULL, USER, rvar, NULL, 4, ROFF(ru_nswap),
|
||||
LONG, "ld", 0},
|
||||
{"nvcsw", "NVCSW", NULL, USER, rvar, NULL, 5, ROFF(ru_nvcsw),
|
||||
LONG, "ld", 0},
|
||||
{"nwchan", "NWCHAN", NULL, LJUST, nwchan, NULL, sizeof(void *) * 2, 0,
|
||||
CHAR, NULL, 0},
|
||||
{"oublk", "OUBLK", NULL, USER, rvar, NULL, 4, ROFF(ru_oublock),
|
||||
LONG, "ld", 0},
|
||||
{"oublock", "", "oublk", 0, NULL, NULL, 0, 0, CHAR, NULL, 0},
|
||||
{"paddr", "PADDR", NULL, 0, kvar, NULL, sizeof(void *) * 2,
|
||||
KOFF(ki_paddr), KPTR, "lx", 0},
|
||||
{"pagein", "PAGEIN", NULL, USER, pagein, NULL, 6, 0, CHAR, NULL, 0},
|
||||
{"pcpu", "", "%cpu", 0, NULL, NULL, 0, 0, CHAR, NULL, 0},
|
||||
{"pending", "", "sig", 0, NULL, NULL, 0, 0, CHAR, NULL, 0},
|
||||
{"pgid", "PGID", NULL, 0, kvar, NULL, PIDLEN, KOFF(ki_pgid), UINT,
|
||||
PIDFMT, 0},
|
||||
{"pid", "PID", NULL, 0, kvar, NULL, PIDLEN, KOFF(ki_pid), UINT,
|
||||
PIDFMT, 0},
|
||||
{"pmem", "", "%mem", 0, NULL, NULL, 0, 0, CHAR, NULL, 0},
|
||||
{"ppid", "PPID", NULL, 0, kvar, NULL, PIDLEN, KOFF(ki_ppid), UINT,
|
||||
PIDFMT, 0},
|
||||
{"pri", "PRI", NULL, 0, pri, NULL, 3, 0, CHAR, NULL, 0},
|
||||
{"re", "RE", NULL, INF127, kvar, NULL, 3, KOFF(ki_swtime), UINT, "d",
|
||||
0},
|
||||
{"rgid", "RGID", NULL, 0, kvar, NULL, UIDLEN, KOFF(ki_rgid),
|
||||
UINT, UIDFMT, 0},
|
||||
{"rgroup", "RGROUP", NULL, LJUST, rgroupname, s_rgroupname,
|
||||
USERLEN, 0, CHAR, NULL, 0},
|
||||
{"rss", "RSS", NULL, 0, kvar, NULL, 6, KOFF(ki_rssize), PGTOK, "ld", 0},
|
||||
{"rtprio", "RTPRIO", NULL, 0, priorityr, NULL, 7, KOFF(ki_pri), CHAR,
|
||||
NULL, 0},
|
||||
{"ruid", "RUID", NULL, 0, kvar, NULL, UIDLEN, KOFF(ki_ruid),
|
||||
UINT, UIDFMT, 0},
|
||||
{"ruser", "RUSER", NULL, LJUST, runame, s_runame, USERLEN,
|
||||
0, CHAR, NULL, 0},
|
||||
{"sid", "SID", NULL, 0, kvar, NULL, PIDLEN, KOFF(ki_sid), UINT,
|
||||
PIDFMT, 0},
|
||||
{"sig", "PENDING", NULL, 0, kvar, NULL, 8, KOFF(ki_siglist), INT,
|
||||
"x", 0},
|
||||
{"sigcatch", "CAUGHT", NULL, 0, kvar, NULL, 8, KOFF(ki_sigcatch),
|
||||
{"cpu", "CPU", NULL, 0, kvar, KOFF(ki_estcpu), UINT, "d", 0},
|
||||
{"cputime", "", "time", 0, NULL, 0, CHAR, NULL, 0},
|
||||
{"egid", "", "gid", 0, NULL, 0, CHAR, NULL, 0},
|
||||
{"egroup", "", "group", 0, NULL, 0, CHAR, NULL, 0},
|
||||
{"emul", "EMUL", NULL, LJUST, emulname, 0, CHAR, NULL, 0},
|
||||
{"etime", "ELAPSED", NULL, USER, elapsed, 0, CHAR, NULL, 0},
|
||||
{"etimes", "ELAPSED", NULL, USER, elapseds, 0, CHAR, NULL, 0},
|
||||
{"euid", "", "uid", 0, NULL, 0, CHAR, NULL, 0},
|
||||
{"f", "F", NULL, 0, kvar, KOFF(ki_flag), INT, "x", 0},
|
||||
{"flags", "", "f", 0, NULL, 0, CHAR, NULL, 0},
|
||||
{"gid", "GID", NULL, 0, kvar, KOFF(ki_groups), UINT, UIDFMT, 0},
|
||||
{"group", "GROUP", NULL, LJUST, egroupname, 0, CHAR, NULL, 0},
|
||||
{"ignored", "", "sigignore", 0, NULL, 0, CHAR, NULL, 0},
|
||||
{"inblk", "INBLK", NULL, USER, rvar, ROFF(ru_inblock), LONG, "ld", 0},
|
||||
{"inblock", "", "inblk", 0, NULL, 0, CHAR, NULL, 0},
|
||||
{"jid", "JID", NULL, 0, kvar, KOFF(ki_jid), INT, "d", 0},
|
||||
{"jobc", "JOBC", NULL, 0, kvar, KOFF(ki_jobc), SHORT, "d", 0},
|
||||
{"ktrace", "KTRACE", NULL, 0, kvar, KOFF(ki_traceflag), INT, "x", 0},
|
||||
{"label", "LABEL", NULL, LJUST, label, 0, CHAR, NULL, 0},
|
||||
{"lim", "LIM", NULL, 0, maxrss, 0, CHAR, NULL, 0},
|
||||
{"lockname", "LOCK", NULL, LJUST, lockname, 0, CHAR, NULL, 0},
|
||||
{"login", "LOGIN", NULL, LJUST, logname, 0, CHAR, NULL, 0},
|
||||
{"logname", "", "login", 0, NULL, 0, CHAR, NULL, 0},
|
||||
{"lstart", "STARTED", NULL, LJUST|USER, lstarted, 0, CHAR, NULL, 0},
|
||||
{"lwp", "LWP", NULL, 0, kvar, KOFF(ki_tid), UINT, LWPFMT, 0},
|
||||
{"majflt", "MAJFLT", NULL, USER, rvar, ROFF(ru_majflt), LONG, "ld", 0},
|
||||
{"minflt", "MINFLT", NULL, USER, rvar, ROFF(ru_minflt), LONG, "ld", 0},
|
||||
{"msgrcv", "MSGRCV", NULL, USER, rvar, ROFF(ru_msgrcv), LONG, "ld", 0},
|
||||
{"msgsnd", "MSGSND", NULL, USER, rvar, ROFF(ru_msgsnd), LONG, "ld", 0},
|
||||
{"mwchan", "MWCHAN", NULL, LJUST, mwchan, 0, CHAR, NULL, 0},
|
||||
{"ni", "", "nice", 0, NULL, 0, CHAR, NULL, 0},
|
||||
{"nice", "NI", NULL, 0, kvar, KOFF(ki_nice), CHAR, "d", 0},
|
||||
{"nivcsw", "NIVCSW", NULL, USER, rvar, ROFF(ru_nivcsw), LONG, "ld", 0},
|
||||
{"nlwp", "NLWP", NULL, 0, kvar, KOFF(ki_numthreads), UINT, NLWPFMT, 0},
|
||||
{"nsignals", "", "nsigs", 0, NULL, 0, CHAR, NULL, 0},
|
||||
{"nsigs", "NSIGS", NULL, USER, rvar, ROFF(ru_nsignals), LONG, "ld", 0},
|
||||
{"nswap", "NSWAP", NULL, USER, rvar, ROFF(ru_nswap), LONG, "ld", 0},
|
||||
{"nvcsw", "NVCSW", NULL, USER, rvar, ROFF(ru_nvcsw), LONG, "ld", 0},
|
||||
{"nwchan", "NWCHAN", NULL, LJUST, nwchan, 0, CHAR, NULL, 0},
|
||||
{"oublk", "OUBLK", NULL, USER, rvar, ROFF(ru_oublock), LONG, "ld", 0},
|
||||
{"oublock", "", "oublk", 0, NULL, 0, CHAR, NULL, 0},
|
||||
{"paddr", "PADDR", NULL, 0, kvar, KOFF(ki_paddr), KPTR, "lx", 0},
|
||||
{"pagein", "PAGEIN", NULL, USER, pagein, 0, CHAR, NULL, 0},
|
||||
{"pcpu", "", "%cpu", 0, NULL, 0, CHAR, NULL, 0},
|
||||
{"pending", "", "sig", 0, NULL, 0, CHAR, NULL, 0},
|
||||
{"pgid", "PGID", NULL, 0, kvar, KOFF(ki_pgid), UINT, PIDFMT, 0},
|
||||
{"pid", "PID", NULL, 0, kvar, KOFF(ki_pid), UINT, PIDFMT, 0},
|
||||
{"pmem", "", "%mem", 0, NULL, 0, CHAR, NULL, 0},
|
||||
{"ppid", "PPID", NULL, 0, kvar, KOFF(ki_ppid), UINT, PIDFMT, 0},
|
||||
{"pri", "PRI", NULL, 0, pri, 0, CHAR, NULL, 0},
|
||||
{"re", "RE", NULL, INF127, kvar, KOFF(ki_swtime), UINT, "d", 0},
|
||||
{"rgid", "RGID", NULL, 0, kvar, KOFF(ki_rgid), UINT, UIDFMT, 0},
|
||||
{"rgroup", "RGROUP", NULL, LJUST, rgroupname, 0, CHAR, NULL, 0},
|
||||
{"rss", "RSS", NULL, 0, kvar, KOFF(ki_rssize), PGTOK, "ld", 0},
|
||||
{"rtprio", "RTPRIO", NULL, 0, priorityr, KOFF(ki_pri), CHAR, NULL, 0},
|
||||
{"ruid", "RUID", NULL, 0, kvar, KOFF(ki_ruid), UINT, UIDFMT, 0},
|
||||
{"ruser", "RUSER", NULL, LJUST, runame, 0, CHAR, NULL, 0},
|
||||
{"sid", "SID", NULL, 0, kvar, KOFF(ki_sid), UINT, PIDFMT, 0},
|
||||
{"sig", "PENDING", NULL, 0, kvar, KOFF(ki_siglist), INT, "x", 0},
|
||||
{"sigcatch", "CAUGHT", NULL, 0, kvar, KOFF(ki_sigcatch), UINT, "x", 0},
|
||||
{"sigignore", "IGNORED", NULL, 0, kvar, KOFF(ki_sigignore),
|
||||
UINT, "x", 0},
|
||||
{"sigignore", "IGNORED", NULL, 0, kvar, NULL, 8, KOFF(ki_sigignore),
|
||||
UINT, "x", 0},
|
||||
{"sigmask", "BLOCKED", NULL, 0, kvar, NULL, 8, KOFF(ki_sigmask),
|
||||
UINT, "x", 0},
|
||||
{"sl", "SL", NULL, INF127, kvar, NULL, 3, KOFF(ki_slptime), UINT, "d",
|
||||
0},
|
||||
{"start", "STARTED", NULL, LJUST|USER, started, NULL, 7, 0, CHAR, NULL,
|
||||
0},
|
||||
{"stat", "", "state", 0, NULL, NULL, 0, 0, CHAR, NULL, 0},
|
||||
{"state", "STAT", NULL, 0, state, NULL, 4, 0, CHAR, NULL, 0},
|
||||
{"svgid", "SVGID", NULL, 0, kvar, NULL, UIDLEN, KOFF(ki_svgid),
|
||||
UINT, UIDFMT, 0},
|
||||
{"svuid", "SVUID", NULL, 0, kvar, NULL, UIDLEN, KOFF(ki_svuid),
|
||||
UINT, UIDFMT, 0},
|
||||
{"systime", "SYSTIME", NULL, USER, systime, s_systime, 15, 0, CHAR,
|
||||
NULL, 0},
|
||||
{"tdaddr", "TDADDR", NULL, 0, kvar, NULL, sizeof(void *) * 2,
|
||||
KOFF(ki_tdaddr), KPTR, "lx", 0},
|
||||
{"tdev", "TDEV", NULL, 0, tdev, NULL, 5, 0, CHAR, NULL, 0},
|
||||
{"tdnam", "TDNAM", NULL, LJUST, tdnam, NULL, COMMLEN, 0, CHAR, NULL, 0},
|
||||
{"time", "TIME", NULL, USER, cputime, s_cputime, 15, 0, CHAR,
|
||||
NULL, 0},
|
||||
{"tpgid", "TPGID", NULL, 0, kvar, NULL, 4, KOFF(ki_tpgid), UINT,
|
||||
PIDFMT, 0},
|
||||
{"tsid", "TSID", NULL, 0, kvar, NULL, PIDLEN, KOFF(ki_tsid), UINT,
|
||||
PIDFMT, 0},
|
||||
{"tsiz", "TSIZ", NULL, 0, kvar, NULL, 4, KOFF(ki_tsize), PGTOK, "ld", 0},
|
||||
{"tt", "TT ", NULL, 0, tname, NULL, 4, 0, CHAR, NULL, 0},
|
||||
{"tty", "TTY", NULL, LJUST, longtname, NULL, 8, 0, CHAR, NULL, 0},
|
||||
{"ucomm", "UCOMM", NULL, LJUST, ucomm, s_comm,
|
||||
COMMLEN + TDNAMLEN + 1, 0, CHAR, NULL, 0},
|
||||
{"uid", "UID", NULL, 0, kvar, NULL, UIDLEN, KOFF(ki_uid), UINT,
|
||||
UIDFMT, 0},
|
||||
{"upr", "UPR", NULL, 0, upr, NULL, 3, 0, CHAR, NULL, 0},
|
||||
{"uprocp", "UPROCP", NULL, 0, kvar, NULL, sizeof(void *) * 2,
|
||||
KOFF(ki_paddr), KPTR, "lx", 0},
|
||||
{"user", "USER", NULL, LJUST, uname, s_uname, USERLEN, 0, CHAR,
|
||||
NULL, 0},
|
||||
{"usertime", "USERTIME", NULL, USER, usertime, s_usertime, 15, 0,
|
||||
CHAR, NULL, 0},
|
||||
{"usrpri", "", "upr", 0, NULL, NULL, 0, 0, CHAR, NULL, 0},
|
||||
{"vsize", "", "vsz", 0, NULL, NULL, 0, 0, CHAR, NULL, 0},
|
||||
{"vsz", "VSZ", NULL, 0, vsize, NULL, 6, 0, CHAR, NULL, 0},
|
||||
{"wchan", "WCHAN", NULL, LJUST, wchan, NULL, 6, 0, CHAR, NULL, 0},
|
||||
{"xstat", "XSTAT", NULL, 0, kvar, NULL, 4, KOFF(ki_xstat), USHORT,
|
||||
"x", 0},
|
||||
{"", NULL, NULL, 0, NULL, NULL, 0, 0, CHAR, NULL, 0},
|
||||
{"sigmask", "BLOCKED", NULL, 0, kvar, KOFF(ki_sigmask), UINT, "x", 0},
|
||||
{"sl", "SL", NULL, INF127, kvar, KOFF(ki_slptime), UINT, "d", 0},
|
||||
{"start", "STARTED", NULL, LJUST|USER, started, 0, CHAR, NULL, 0},
|
||||
{"stat", "", "state", 0, NULL, 0, CHAR, NULL, 0},
|
||||
{"state", "STAT", NULL, LJUST, state, 0, CHAR, NULL, 0},
|
||||
{"svgid", "SVGID", NULL, 0, kvar, KOFF(ki_svgid), UINT, UIDFMT, 0},
|
||||
{"svuid", "SVUID", NULL, 0, kvar, KOFF(ki_svuid), UINT, UIDFMT, 0},
|
||||
{"systime", "SYSTIME", NULL, USER, systime, 0, CHAR, NULL, 0},
|
||||
{"tdaddr", "TDADDR", NULL, 0, kvar, KOFF(ki_tdaddr), KPTR, "lx", 0},
|
||||
{"tdev", "TDEV", NULL, 0, tdev, 0, CHAR, NULL, 0},
|
||||
{"tdnam", "TDNAM", NULL, LJUST, tdnam, 0, CHAR, NULL, 0},
|
||||
{"time", "TIME", NULL, USER, cputime, 0, CHAR, NULL, 0},
|
||||
{"tpgid", "TPGID", NULL, 0, kvar, KOFF(ki_tpgid), UINT, PIDFMT, 0},
|
||||
{"tsid", "TSID", NULL, 0, kvar, KOFF(ki_tsid), UINT, PIDFMT, 0},
|
||||
{"tsiz", "TSIZ", NULL, 0, kvar, KOFF(ki_tsize), PGTOK, "ld", 0},
|
||||
{"tt", "TT ", NULL, 0, tname, 0, CHAR, NULL, 0},
|
||||
{"tty", "TTY", NULL, LJUST, longtname, 0, CHAR, NULL, 0},
|
||||
{"ucomm", "UCOMM", NULL, LJUST, ucomm, 0, CHAR, NULL, 0},
|
||||
{"uid", "UID", NULL, 0, kvar, KOFF(ki_uid), UINT, UIDFMT, 0},
|
||||
{"upr", "UPR", NULL, 0, upr, 0, CHAR, NULL, 0},
|
||||
{"uprocp", "UPROCP", NULL, 0, kvar, KOFF(ki_paddr), KPTR, "lx", 0},
|
||||
{"user", "USER", NULL, LJUST, uname, 0, CHAR, NULL, 0},
|
||||
{"usertime", "USERTIME", NULL, USER, usertime, 0, CHAR, NULL, 0},
|
||||
{"usrpri", "", "upr", 0, NULL, 0, CHAR, NULL, 0},
|
||||
{"vsize", "", "vsz", 0, NULL, 0, CHAR, NULL, 0},
|
||||
{"vsz", "VSZ", NULL, 0, vsize, 0, CHAR, NULL, 0},
|
||||
{"wchan", "WCHAN", NULL, LJUST, wchan, 0, CHAR, NULL, 0},
|
||||
{"xstat", "XSTAT", NULL, 0, kvar, KOFF(ki_xstat), USHORT, "x", 0},
|
||||
{"", NULL, NULL, 0, NULL, 0, CHAR, NULL, 0},
|
||||
};
|
||||
|
||||
void
|
||||
|
585
bin/ps/print.c
585
bin/ps/print.c
File diff suppressed because it is too large
Load Diff
103
bin/ps/ps.c
103
bin/ps/ps.c
@ -99,14 +99,12 @@ time_t now; /* Current time(3) value */
|
||||
int rawcpu; /* -C */
|
||||
int sumrusage; /* -S */
|
||||
int termwidth; /* Width of the screen (0 == infinity). */
|
||||
int totwidth; /* Calculated-width of requested variables. */
|
||||
int showthreads; /* will threads be shown? */
|
||||
|
||||
struct velisthead varlist = STAILQ_HEAD_INITIALIZER(varlist);
|
||||
|
||||
static int forceuread = DEF_UREAD; /* Do extra work to get u-area. */
|
||||
static kvm_t *kd;
|
||||
static KINFO *kinfo;
|
||||
static int needcomm; /* -o "command" */
|
||||
static int needenv; /* -e */
|
||||
static int needuser; /* -o "user" */
|
||||
@ -139,7 +137,7 @@ static int addelem_tty(struct listinfo *, const char *);
|
||||
static int addelem_uid(struct listinfo *, const char *);
|
||||
static void add_list(struct listinfo *, const char *);
|
||||
static void descendant_sort(KINFO *, int);
|
||||
static void dynsizevars(KINFO *);
|
||||
static void format_output(KINFO *);
|
||||
static void *expand_list(struct listinfo *);
|
||||
static const char *
|
||||
fmt(char **(*)(kvm_t *, const struct kinfo_proc *, int),
|
||||
@ -172,12 +170,13 @@ main(int argc, char *argv[])
|
||||
struct listinfo gidlist, pgrplist, pidlist;
|
||||
struct listinfo ruidlist, sesslist, ttylist, uidlist;
|
||||
struct kinfo_proc *kp;
|
||||
KINFO *next_KINFO;
|
||||
KINFO *kinfo = NULL, *next_KINFO;
|
||||
KINFO_STR *ks;
|
||||
struct varent *vent;
|
||||
struct winsize ws;
|
||||
const char *nlistf, *memf;
|
||||
const char *nlistf, *memf, *fmtstr, *str;
|
||||
char *cols;
|
||||
int all, ch, elem, flag, _fmt, i, lineno;
|
||||
int all, ch, elem, flag, _fmt, i, lineno, linelen, left;
|
||||
int descendancy, nentries, nkept, nselectors;
|
||||
int prtheader, wflag, what, xkeep, xkeep_implied;
|
||||
char errbuf[_POSIX2_LINE_MAX];
|
||||
@ -588,19 +587,16 @@ main(int argc, char *argv[])
|
||||
kp->ki_dsize + kp->ki_ssize;
|
||||
if (needuser)
|
||||
saveuser(next_KINFO);
|
||||
dynsizevars(next_KINFO);
|
||||
nkept++;
|
||||
}
|
||||
}
|
||||
|
||||
sizevars();
|
||||
|
||||
/*
|
||||
* print header
|
||||
*/
|
||||
printheader();
|
||||
if (nkept == 0)
|
||||
if (nkept == 0) {
|
||||
printheader();
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/*
|
||||
* sort proc list
|
||||
@ -613,14 +609,59 @@ main(int argc, char *argv[])
|
||||
if (descendancy)
|
||||
descendant_sort(kinfo, nkept);
|
||||
|
||||
|
||||
/*
|
||||
* For each process, call each variable output function.
|
||||
* Prepare formatted output.
|
||||
*/
|
||||
for (i = 0; i < nkept; i++)
|
||||
format_output(&kinfo[i]);
|
||||
|
||||
/*
|
||||
* Print header.
|
||||
*/
|
||||
printheader();
|
||||
|
||||
/*
|
||||
* Output formatted lines.
|
||||
*/
|
||||
for (i = lineno = 0; i < nkept; i++) {
|
||||
linelen = 0;
|
||||
STAILQ_FOREACH(vent, &varlist, next_ve) {
|
||||
(vent->var->oproc)(&kinfo[i], vent);
|
||||
if (STAILQ_NEXT(vent, next_ve) != NULL)
|
||||
if (vent->var->flag & LJUST)
|
||||
fmtstr = "%-*s";
|
||||
else
|
||||
fmtstr = "%*s";
|
||||
|
||||
ks = STAILQ_FIRST(&kinfo[i].ki_ks);
|
||||
STAILQ_REMOVE_HEAD(&kinfo[i].ki_ks, ks_next);
|
||||
/* Truncate rightmost column if neccessary. */
|
||||
if (STAILQ_NEXT(vent, next_ve) == NULL &&
|
||||
termwidth != UNLIMITED && ks->ks_str != NULL) {
|
||||
left = termwidth - linelen;
|
||||
if (left > 0 && left < (int)strlen(ks->ks_str))
|
||||
ks->ks_str[left] = '\0';
|
||||
}
|
||||
str = ks->ks_str;
|
||||
if (str == NULL)
|
||||
str = "-";
|
||||
/* No padding for the last column, if it's LJUST. */
|
||||
if (STAILQ_NEXT(vent, next_ve) == NULL &&
|
||||
vent->var->flag & LJUST)
|
||||
linelen += printf(fmtstr, 0, str);
|
||||
else
|
||||
linelen += printf(fmtstr, vent->var->width, str);
|
||||
|
||||
if (ks->ks_str != NULL) {
|
||||
free(ks->ks_str);
|
||||
ks->ks_str = NULL;
|
||||
}
|
||||
free(ks);
|
||||
ks = NULL;
|
||||
|
||||
if (STAILQ_NEXT(vent, next_ve) != NULL) {
|
||||
(void)putchar(' ');
|
||||
linelen++;
|
||||
}
|
||||
}
|
||||
(void)putchar('\n');
|
||||
if (prtheader && lineno++ == prtheader - 4) {
|
||||
@ -1078,10 +1119,6 @@ scanvars(void)
|
||||
|
||||
STAILQ_FOREACH(vent, &varlist, next_ve) {
|
||||
v = vent->var;
|
||||
if (v->sproc != NULL) {
|
||||
v->dwidth = v->width;
|
||||
v->width = 0;
|
||||
}
|
||||
if (v->flag & USER)
|
||||
needuser = 1;
|
||||
if (v->flag & COMM)
|
||||
@ -1090,21 +1127,29 @@ scanvars(void)
|
||||
}
|
||||
|
||||
static void
|
||||
dynsizevars(KINFO *ki)
|
||||
format_output(KINFO *ki)
|
||||
{
|
||||
struct varent *vent;
|
||||
VAR *v;
|
||||
int i;
|
||||
KINFO_STR *ks;
|
||||
char *str;
|
||||
int len;
|
||||
|
||||
STAILQ_INIT(&ki->ki_ks);
|
||||
STAILQ_FOREACH(vent, &varlist, next_ve) {
|
||||
v = vent->var;
|
||||
if (v->sproc == NULL)
|
||||
continue;
|
||||
i = (v->sproc)(ki);
|
||||
if (v->width < i)
|
||||
v->width = i;
|
||||
if (v->width > v->dwidth)
|
||||
v->width = v->dwidth;
|
||||
str = (v->oproc)(ki, vent);
|
||||
ks = malloc(sizeof(*ks));
|
||||
if (ks == NULL)
|
||||
errx(1, "malloc failed");
|
||||
ks->ks_str = str;
|
||||
STAILQ_INSERT_TAIL(&ki->ki_ks, ks, ks_next);
|
||||
if (str != NULL) {
|
||||
len = strlen(str);
|
||||
} else
|
||||
len = 1; /* "-" */
|
||||
if (v->width < len)
|
||||
v->width = len;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1120,9 +1165,7 @@ sizevars(void)
|
||||
i = strlen(vent->header);
|
||||
if (v->width < i)
|
||||
v->width = i;
|
||||
totwidth += v->width + 1; /* +1 for space */
|
||||
}
|
||||
totwidth--;
|
||||
}
|
||||
|
||||
static const char *
|
||||
|
17
bin/ps/ps.h
17
bin/ps/ps.h
@ -35,6 +35,11 @@
|
||||
#define UNLIMITED 0 /* unlimited terminal width */
|
||||
enum type { CHAR, UCHAR, SHORT, USHORT, INT, UINT, LONG, ULONG, KPTR, PGTOK };
|
||||
|
||||
typedef struct kinfo_str {
|
||||
STAILQ_ENTRY(kinfo_str) ks_next;
|
||||
char *ks_str; /* formatted string */
|
||||
} KINFO_STR;
|
||||
|
||||
typedef struct kinfo {
|
||||
struct kinfo_proc *ki_p; /* kinfo_proc structure */
|
||||
char *ki_args; /* exec args */
|
||||
@ -46,6 +51,7 @@ typedef struct kinfo {
|
||||
int level; /* used in decendant_sort() */
|
||||
char *prefix; /* calculated in decendant_sort() */
|
||||
} ki_d;
|
||||
STAILQ_HEAD(, kinfo_str) ki_ks;
|
||||
} KINFO;
|
||||
|
||||
/* Variables. */
|
||||
@ -65,10 +71,7 @@ typedef struct var {
|
||||
#define INF127 0x10 /* values >127 displayed as 127 */
|
||||
u_int flag;
|
||||
/* output routine */
|
||||
void (*oproc)(struct kinfo *, struct varent *);
|
||||
/* sizing routine */
|
||||
int (*sproc)(struct kinfo *);
|
||||
short width; /* printing width */
|
||||
char *(*oproc)(struct kinfo *, struct varent *);
|
||||
/*
|
||||
* The following (optional) elements are hooks for passing information
|
||||
* to the generic output routine pvar (which prints simple elements
|
||||
@ -77,10 +80,8 @@ typedef struct var {
|
||||
size_t off; /* offset in structure */
|
||||
enum type type; /* type of element */
|
||||
const char *fmt; /* printf format */
|
||||
short dwidth; /* dynamic printing width */
|
||||
/*
|
||||
* glue to link selected fields together
|
||||
*/
|
||||
|
||||
short width; /* calculated width */
|
||||
} VAR;
|
||||
|
||||
#include "extern.h"
|
||||
|
Loading…
Reference in New Issue
Block a user