Include the thread name along with the command name when displaying the
command name of a thread from a multi-threaded process that doesn't have an available argument list (such as kernel processes) and threads display is enabled via -H. Reviewed by: alfred, delphij, eric@vangyzen.net MFC after: 1 week
This commit is contained in:
parent
38d90616e6
commit
1c67ef129f
@ -51,7 +51,7 @@ char *elapsed(KINFO *, VARENT *);
|
|||||||
char *elapseds(KINFO *, VARENT *);
|
char *elapseds(KINFO *, VARENT *);
|
||||||
char *emulname(KINFO *, VARENT *);
|
char *emulname(KINFO *, VARENT *);
|
||||||
VARENT *find_varentry(VAR *);
|
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 *);
|
double getpcpu(const KINFO *);
|
||||||
char *kvar(KINFO *, VARENT *);
|
char *kvar(KINFO *, VARENT *);
|
||||||
char *label(KINFO *, VARENT *);
|
char *label(KINFO *, VARENT *);
|
||||||
|
11
bin/ps/fmt.c
11
bin/ps/fmt.c
@ -105,7 +105,7 @@ cmdpart(char *arg0)
|
|||||||
}
|
}
|
||||||
|
|
||||||
const char *
|
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;
|
size_t len;
|
||||||
char *ap, *cp;
|
char *ap, *cp;
|
||||||
@ -122,9 +122,14 @@ fmt_argv(char **argv, char *cmd, size_t maxlen)
|
|||||||
cp = malloc(len);
|
cp = malloc(len);
|
||||||
if (cp == NULL)
|
if (cp == NULL)
|
||||||
errx(1, "malloc failed");
|
errx(1, "malloc failed");
|
||||||
if (ap == NULL)
|
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);
|
sprintf(cp, "[%.*s]", (int)maxlen, cmd);
|
||||||
else if (strncmp(cmdpart(argv[0]), cmd, maxlen) != 0)
|
} else if (strncmp(cmdpart(argv[0]), cmd, maxlen) != 0)
|
||||||
sprintf(cp, "%s (%.*s)", ap, (int)maxlen, cmd);
|
sprintf(cp, "%s (%.*s)", ap, (int)maxlen, cmd);
|
||||||
else
|
else
|
||||||
strcpy(cp, ap);
|
strcpy(cp, ap);
|
||||||
|
11
bin/ps/ps.c
11
bin/ps/ps.c
@ -141,7 +141,7 @@ static void format_output(KINFO *);
|
|||||||
static void *expand_list(struct listinfo *);
|
static void *expand_list(struct listinfo *);
|
||||||
static const char *
|
static const char *
|
||||||
fmt(char **(*)(kvm_t *, const struct kinfo_proc *, int),
|
fmt(char **(*)(kvm_t *, const struct kinfo_proc *, int),
|
||||||
KINFO *, char *, int);
|
KINFO *, char *, char *, int);
|
||||||
static void free_list(struct listinfo *);
|
static void free_list(struct listinfo *);
|
||||||
static void init_list(struct listinfo *, addelem_rtn, int, const char *);
|
static void init_list(struct listinfo *, addelem_rtn, int, const char *);
|
||||||
static char *kludge_oldps_options(const char *, char *, const char *);
|
static char *kludge_oldps_options(const char *, char *, const char *);
|
||||||
@ -1163,11 +1163,12 @@ sizevars(void)
|
|||||||
|
|
||||||
static const char *
|
static const char *
|
||||||
fmt(char **(*fn)(kvm_t *, const struct kinfo_proc *, int), KINFO *ki,
|
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;
|
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);
|
return (s);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1195,7 +1196,7 @@ saveuser(KINFO *ki)
|
|||||||
ki->ki_args = strdup("<defunct>");
|
ki->ki_args = strdup("<defunct>");
|
||||||
else if (UREADOK(ki) || (ki->ki_p->ki_args != NULL))
|
else if (UREADOK(ki) || (ki->ki_p->ki_args != NULL))
|
||||||
ki->ki_args = strdup(fmt(kvm_getargv, ki,
|
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
|
else
|
||||||
asprintf(&ki->ki_args, "(%s)", ki->ki_p->ki_comm);
|
asprintf(&ki->ki_args, "(%s)", ki->ki_p->ki_comm);
|
||||||
if (ki->ki_args == NULL)
|
if (ki->ki_args == NULL)
|
||||||
@ -1206,7 +1207,7 @@ saveuser(KINFO *ki)
|
|||||||
if (needenv) {
|
if (needenv) {
|
||||||
if (UREADOK(ki))
|
if (UREADOK(ki))
|
||||||
ki->ki_env = strdup(fmt(kvm_getenvv, ki,
|
ki->ki_env = strdup(fmt(kvm_getenvv, ki,
|
||||||
(char *)NULL, 0));
|
(char *)NULL, (char *)NULL, 0));
|
||||||
else
|
else
|
||||||
ki->ki_env = strdup("()");
|
ki->ki_env = strdup("()");
|
||||||
if (ki->ki_env == NULL)
|
if (ki->ki_env == NULL)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user