From 033340171accba5dc74bdef5061ba2dea0df5a3e Mon Sep 17 00:00:00 2001 From: Juli Mallett Date: Thu, 6 Jun 2002 20:21:47 +0000 Subject: [PATCH] SUSv3 conform on the "comm" and "args" formats, and make correct the "command" format, since it's BSDlike, and "comm" is actually different. --- bin/ps/extern.h | 1 + bin/ps/keyword.c | 8 +++++--- bin/ps/print.c | 30 ++++++++++++++++++++++++++++++ bin/ps/ps.1 | 6 +++++- 4 files changed, 41 insertions(+), 4 deletions(-) diff --git a/bin/ps/extern.h b/bin/ps/extern.h index ecb86f078de..2ea5724affc 100644 --- a/bin/ps/extern.h +++ b/bin/ps/extern.h @@ -45,6 +45,7 @@ extern int sumrusage, termwidth, totwidth; extern VARENT *vhead; __BEGIN_DECLS +void arguments(KINFO *, VARENT *); void command(KINFO *, VARENT *); void cputime(KINFO *, VARENT *); int donlist(void); diff --git a/bin/ps/keyword.c b/bin/ps/keyword.c index 729a7c4613f..b54cb43fdc5 100644 --- a/bin/ps/keyword.c +++ b/bin/ps/keyword.c @@ -85,12 +85,14 @@ static VAR var[] = { {"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, + CHAR, NULL, 0}, {"blocked", "", "sigmask", 0, NULL, NULL, 0, 0, CHAR, NULL, 0}, {"caught", "", "sigcatch", 0, NULL, NULL, 0, 0, CHAR, NULL, 0}, - {"comm", "COMMAND", NULL, COMM|LJUST|USER, command, NULL, 16, 0, + {"comm", "COMMAND", NULL, LJUST, ucomm, NULL, MAXCOMLEN, 0, CHAR, + NULL, 0}, + {"command", "COMMAND", NULL, COMM|LJUST|USER, command, NULL, 16, 0, CHAR, NULL, 0}, - {"command", "COMMAND", NULL, COMM|LJUST|USER, command, NULL, 16, - 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}, diff --git a/bin/ps/print.c b/bin/ps/print.c index f885770dfe0..e3c3a3e4cbb 100644 --- a/bin/ps/print.c +++ b/bin/ps/print.c @@ -90,6 +90,36 @@ printheader(void) (void)putchar('\n'); } +void +arguments(KINFO *k, VARENT *ve) +{ + VAR *v; + int left; + char *cp, *vis_args; + + v = ve->var; + + if ((vis_args = malloc(strlen(k->ki_args) * 4 + 1)) == NULL) + errx(1, "malloc failed"); + strvis(vis_args, k->ki_args, VIS_TAB | VIS_NL | VIS_NOSLASH); + + if (ve->next == NULL) { + /* last field */ + if (termwidth == UNLIMITED) { + (void)printf("%s", vis_args); + } else { + left = termwidth - (totwidth - v->width); + if (left < 1) /* already wrapped, just use std width */ + left = v->width; + for (cp = vis_args; --left >= 0 && *cp != '\0';) + (void)putchar(*cp++); + } + } else { + (void)printf("%-*.*s", v->width, v->width, vis_args); + } + free(vis_args); +} + void command(KINFO *k, VARENT *ve) { diff --git a/bin/ps/ps.1 b/bin/ps/ps.1 index 43fbdef7646..80f541d30ca 100644 --- a/bin/ps/ps.1 +++ b/bin/ps/ps.1 @@ -370,8 +370,12 @@ percentage cpu usage (alias pcpu) percentage memory usage (alias pmem) .It acflag accounting flag (alias acflg) +.It args +command and arguments .It comm -command and arguments (alias command) +command +.It command +command and arguments .It cpu short-term cpu usage factor (for scheduling) .It flags