diff --git a/bin/ps/extern.h b/bin/ps/extern.h index 930b85b0bcaa..eb9b2cfeee5b 100644 --- a/bin/ps/extern.h +++ b/bin/ps/extern.h @@ -51,7 +51,7 @@ char *elapsed(KINFO *, VARENT *); char *elapseds(KINFO *, VARENT *); char *emulname(KINFO *, VARENT *); VARENT *find_varentry(VAR *); -const char *fmt_argv(char **, char *, size_t); +const char *fmt_argv(char **, char *, char *, size_t); double getpcpu(const KINFO *); char *kvar(KINFO *, VARENT *); char *label(KINFO *, VARENT *); diff --git a/bin/ps/fmt.c b/bin/ps/fmt.c index 1e9fed8710f0..4d7b1209a980 100644 --- a/bin/ps/fmt.c +++ b/bin/ps/fmt.c @@ -105,7 +105,7 @@ cmdpart(char *arg0) } const char * -fmt_argv(char **argv, char *cmd, size_t maxlen) +fmt_argv(char **argv, char *cmd, char *thread, size_t maxlen) { size_t len; char *ap, *cp; @@ -122,9 +122,14 @@ fmt_argv(char **argv, char *cmd, size_t maxlen) cp = malloc(len); if (cp == NULL) errx(1, "malloc failed"); - if (ap == NULL) - sprintf(cp, "[%.*s]", (int)maxlen, cmd); - else if (strncmp(cmdpart(argv[0]), cmd, maxlen) != 0) + if (ap == NULL) { + if (showthreads && thread != NULL) { + asprintf(&ap, "%s/%s", cmd, thread); + sprintf(cp, "[%.*s]", (int)maxlen, ap); + free(ap); + } else + sprintf(cp, "[%.*s]", (int)maxlen, cmd); + } else if (strncmp(cmdpart(argv[0]), cmd, maxlen) != 0) sprintf(cp, "%s (%.*s)", ap, (int)maxlen, cmd); else strcpy(cp, ap); diff --git a/bin/ps/ps.c b/bin/ps/ps.c index e9fc5fab5e2a..8a05ebc6f598 100644 --- a/bin/ps/ps.c +++ b/bin/ps/ps.c @@ -141,7 +141,7 @@ static void format_output(KINFO *); static void *expand_list(struct listinfo *); static const char * fmt(char **(*)(kvm_t *, const struct kinfo_proc *, int), - KINFO *, char *, int); + KINFO *, char *, char *, int); static void free_list(struct listinfo *); static void init_list(struct listinfo *, addelem_rtn, int, const char *); static char *kludge_oldps_options(const char *, char *, const char *); @@ -1163,11 +1163,12 @@ sizevars(void) static const char * fmt(char **(*fn)(kvm_t *, const struct kinfo_proc *, int), KINFO *ki, - char *comm, int maxlen) + char *comm, char *thread, int maxlen) { const char *s; - s = fmt_argv((*fn)(kd, ki->ki_p, termwidth), comm, maxlen); + s = fmt_argv((*fn)(kd, ki->ki_p, termwidth), comm, + ki->ki_p->ki_numthreads > 1 ? thread : NULL, maxlen); return (s); } @@ -1195,7 +1196,7 @@ saveuser(KINFO *ki) ki->ki_args = strdup(""); else if (UREADOK(ki) || (ki->ki_p->ki_args != NULL)) ki->ki_args = strdup(fmt(kvm_getargv, ki, - ki->ki_p->ki_comm, MAXCOMLEN)); + ki->ki_p->ki_comm, ki->ki_p->ki_tdname, MAXCOMLEN)); else asprintf(&ki->ki_args, "(%s)", ki->ki_p->ki_comm); if (ki->ki_args == NULL) @@ -1206,7 +1207,7 @@ saveuser(KINFO *ki) if (needenv) { if (UREADOK(ki)) ki->ki_env = strdup(fmt(kvm_getenvv, ki, - (char *)NULL, 0)); + (char *)NULL, (char *)NULL, 0)); else ki->ki_env = strdup("()"); if (ki->ki_env == NULL)