summaryrefslogtreecommitdiffstats
path: root/bin/ps/print.c
diff options
context:
space:
mode:
authorbrian <brian@FreeBSD.org>2009-05-17 04:00:43 +0000
committerbrian <brian@FreeBSD.org>2009-05-17 04:00:43 +0000
commit04ab6b4b29dd329da0b15b1fb9d352ad46345130 (patch)
tree3ea0851a957e0b79596c05ac389dff8adbab3743 /bin/ps/print.c
parent33504763e76102ecd6efe8f618b9cf7d9f535a5a (diff)
downloadFreeBSD-src-04ab6b4b29dd329da0b15b1fb9d352ad46345130.zip
FreeBSD-src-04ab6b4b29dd329da0b15b1fb9d352ad46345130.tar.gz
Add a -d option to ps to display descendant info with the output.
This is similar to linux's -H (or -f) switch. MFC after: 3 weeks
Diffstat (limited to 'bin/ps/print.c')
-rw-r--r--bin/ps/print.c33
1 files changed, 23 insertions, 10 deletions
diff --git a/bin/ps/print.c b/bin/ps/print.c
index 3ae37fc..1bfce04 100644
--- a/bin/ps/print.c
+++ b/bin/ps/print.c
@@ -130,9 +130,11 @@ command(KINFO *k, VARENT *ve)
if (cflag) {
/* If it is the last field, then don't pad */
if (STAILQ_NEXT(ve, next_ve) == NULL) {
+ if (k->ki_d.prefix)
+ (void)printf("%s", k->ki_d.prefix);
(void)printf("%s", k->ki_p->ki_comm);
if (showthreads && k->ki_p->ki_numthreads > 1)
- printf("/%s", k->ki_p->ki_ocomm);
+ (void)printf("/%s", k->ki_p->ki_ocomm);
} else
(void)printf("%-*s", v->width, k->ki_p->ki_comm);
return;
@@ -140,16 +142,22 @@ command(KINFO *k, VARENT *ve)
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 (k->ki_env) {
- if ((vis_env = malloc(strlen(k->ki_env) * 4 + 1)) == NULL)
- errx(1, "malloc failed");
- strvis(vis_env, k->ki_env, VIS_TAB | VIS_NL | VIS_NOSLASH);
- } else
- vis_env = NULL;
if (STAILQ_NEXT(ve, next_ve) == NULL) {
/* last field */
+
+ if (k->ki_env) {
+ if ((vis_env = malloc(strlen(k->ki_env) * 4 + 1))
+ == NULL)
+ errx(1, "malloc failed");
+ strvis(vis_env, k->ki_env,
+ VIS_TAB | VIS_NL | VIS_NOSLASH);
+ } else
+ vis_env = NULL;
+
if (termwidth == UNLIMITED) {
+ if (k->ki_d.prefix)
+ (void)printf("%s", k->ki_d.prefix);
if (vis_env)
(void)printf("%s ", vis_env);
(void)printf("%s", vis_args);
@@ -157,6 +165,9 @@ command(KINFO *k, VARENT *ve)
left = termwidth - (totwidth - v->width);
if (left < 1) /* already wrapped, just use std width */
left = v->width;
+ if ((cp = k->ki_d.prefix) != NULL)
+ while (--left >= 0 && *cp)
+ (void)putchar(*cp++);
if ((cp = vis_env) != NULL) {
while (--left >= 0 && *cp)
(void)putchar(*cp++);
@@ -166,12 +177,12 @@ command(KINFO *k, VARENT *ve)
for (cp = vis_args; --left >= 0 && *cp != '\0';)
(void)putchar(*cp++);
}
+ if (vis_env != NULL)
+ free(vis_env);
} else
- /* XXX env? */
+ /* ki_d.prefix & ki_env aren't shown for interim fields */
(void)printf("%-*.*s", v->width, v->width, vis_args);
free(vis_args);
- if (vis_env != NULL)
- free(vis_env);
}
void
@@ -182,6 +193,8 @@ ucomm(KINFO *k, VARENT *ve)
v = ve->var;
if (STAILQ_NEXT(ve, next_ve) == NULL) { /* last field, don't pad */
+ if (k->ki_d.prefix)
+ (void)printf("%s", k->ki_d.prefix);
(void)printf("%s", k->ki_p->ki_comm);
if (showthreads && k->ki_p->ki_numthreads > 1)
printf("/%s", k->ki_p->ki_ocomm);
OpenPOWER on IntegriCloud