diff --git a/bin/ps/extern.h b/bin/ps/extern.h index a322d568b3ae..7c684601b669 100644 --- a/bin/ps/extern.h +++ b/bin/ps/extern.h @@ -77,5 +77,6 @@ void uname(KINFO *, VARENT *); int s_uname(KINFO *); void vsize(KINFO *, VARENT *); void wchan(KINFO *, VARENT *); +void mwchan(KINFO *, VARENT *); void lattr(KINFO *, VARENT *); __END_DECLS diff --git a/bin/ps/keyword.c b/bin/ps/keyword.c index b5cc1524ef4c..e1ff7ba86070 100644 --- a/bin/ps/keyword.c +++ b/bin/ps/keyword.c @@ -119,6 +119,7 @@ static VAR var[] = { LONG, "ld", 0}, {"mtxname", "MUTEX", NULL, LJUST, mtxname, NULL, 6, 0, CHAR, NULL, 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}, diff --git a/bin/ps/print.c b/bin/ps/print.c index 4de0dd792e68..74e7f8fc686a 100644 --- a/bin/ps/print.c +++ b/bin/ps/print.c @@ -401,6 +401,24 @@ wchan(KINFO *k, VARENT *ve) { VAR *v; + v = ve->var; + if (k->ki_p->ki_wchan) { + if (k->ki_p->ki_wmesg[0] != 0) + (void)printf("%-*.*s", v->width, v->width, + k->ki_p->ki_wmesg); + else + (void)printf("%-*lx", v->width, + (long)k->ki_p->ki_wchan); + } else { + (void)printf("%-*s", v->width, "-"); + } +} + +void +mwchan(KINFO *k, VARENT *ve) +{ + VAR *v; + v = ve->var; if (k->ki_p->ki_wchan) { if (k->ki_p->ki_wmesg[0] != 0) @@ -410,7 +428,12 @@ wchan(KINFO *k, VARENT *ve) (void)printf("%-*lx", v->width, (long)k->ki_p->ki_wchan); } else if (k->ki_p->ki_kiflag & KI_MTXBLOCK) { - (void)printf("%-*.*s", v->width, v->width, k->ki_p->ki_mtxname); + if (k->ki_p->ki_mtxname[0]) { + (void)printf("%-*.*s", v->width, v->width, + k->ki_p->ki_mtxname); + } else { + (void)printf("%-*s", v->width, "???"); + } } else { (void)printf("%-*s", v->width, "-"); } diff --git a/bin/ps/ps.1 b/bin/ps/ps.1 index b9237e824558..32402e710f90 100644 --- a/bin/ps/ps.1 +++ b/bin/ps/ps.1 @@ -106,7 +106,7 @@ user, pid, ppid, pgid, jobc, state, tt, time and command. List the set of available keywords. .It Fl l Display information associated with the following keywords: -uid, pid, ppid, cpu, pri, nice, vsz, rss, wchan, state, tt, time +uid, pid, ppid, cpu, pri, nice, vsz, rss, mwchan, state, tt, time and command. .It Fl M Extract values associated with the name list from the specified core @@ -234,6 +234,10 @@ that the process is currently blocked on. If the name is invalid or unknown, then .Dq ???\& is displayed. +.It mwchan +The event name if the process is blocked normally, or the mutex name if +the process is blocked on a mutex. See the wchan and mtxname keywords +for details. .It nice The process scheduling increment (see .Xr setpriority 2 ) . @@ -393,6 +397,8 @@ total messages sent (writes on pipes/sockets) .It mtxname .Xr mutex 9 currently blocked on (as a symbolic name) +.It mwchan +wait channel or mutex currently blocked on .It nice nice value (alias ni) .It nivcsw diff --git a/bin/ps/ps.c b/bin/ps/ps.c index 0897ccbced1e..55445e72da8c 100644 --- a/bin/ps/ps.c +++ b/bin/ps/ps.c @@ -103,7 +103,7 @@ static uid_t *getuids(const char *, int *); static char dfmt[] = "pid tt state time command"; static char jfmt[] = "user pid ppid pgid jobc state tt time command"; -static char lfmt[] = "uid pid ppid cpu pri nice vsz rss wchan state tt time command"; +static char lfmt[] = "uid pid ppid cpu pri nice vsz rss mwchan state tt time command"; static char o1[] = "pid"; static char o2[] = "tt state time command"; static char ufmt[] = "user pid %cpu %mem vsz rss tt state start time command";