Print this page
8158 Want named threads API
9857 proc manpages should have LIBRARY section

@@ -25,11 +25,11 @@
  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
 /*
- * Copyright (c) 2012, Joyent, Inc. All rights reserved.
+ * Copyright (c) 2018, Joyent, Inc.
  */
 
 /*      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
 /*        All Rights Reserved   */
 

@@ -106,10 +106,11 @@
         F_PPID,         /* parent process id */
         F_PGID,         /* process group id */
         F_SID,          /* session id */
         F_PSR,          /* bound processor */
         F_LWP,          /* lwp-id */
+        F_LWPNAME,      /* lwp name */
         F_NLWP,         /* number of lwps */
         F_OPRI,         /* old priority (obsolete) */
         F_PRI,          /* new priority */
         F_F,            /* process flags */
         F_S,            /* letter indicating the state */

@@ -175,10 +176,11 @@
         { "ppid",       "PPID",         5,      5       },
         { "pgid",       "PGID",         5,      5       },
         { "sid",        "SID",          5,      5       },
         { "psr",        "PSR",          3,      2       },
         { "lwp",        "LWP",          6,      2       },
+        { "lwpname",    "LWPNAME",      32,     8       },
         { "nlwp",       "NLWP",         4,      2       },
         { "opri",       "PRI",          3,      2       },
         { "pri",        "PRI",          3,      2       },
         { "f",          "F",            2,      2       },
         { "s",          "S",            1,      1       },

@@ -801,10 +803,11 @@
                                 switch (f->fname) {
                                 case F_TTY:
                                         (void) printf("%-*s",
                                             f->width, f->header);
                                         break;
+                                case F_LWPNAME:
                                 case F_FNAME:
                                 case F_COMM:
                                 case F_ARGS:
                                         /*
                                          * Print these headers full width

@@ -1176,11 +1179,12 @@
                                 header++;
                 }
         }
         for (df = &fname[0]; df < &fname[NFIELDS]; df++)
                 if (strcmp(name, df->fname) == 0) {
-                        if (strcmp(name, "lwp") == 0)
+                        if (strcmp(name, "lwp") == 0 ||
+                            strcmp(name, "lwpname") == 0)
                                 Lflg++;
                         break;
                 }
         if (df >= &fname[NFIELDS]) {
                 (void) fprintf(stderr,

@@ -1752,10 +1756,31 @@
                         (void) printf("%*d", width, psinfo->pr_lwp.pr_bindpro);
                 break;
         case F_LWP:
                 (void) printf("%*d", width, (int)psinfo->pr_lwp.pr_lwpid);
                 break;
+        case F_LWPNAME: {
+                char lwpname[THREAD_NAME_MAX] = "";
+                char *path = NULL;
+                int fd;
+
+                if (asprintf(&path, "%s/%d/lwp/%d/lwpname", procdir,
+                    (int)psinfo->pr_pid, (int)psinfo->pr_lwp.pr_lwpid) != -1 &&
+                    (fd = open(path, O_RDONLY)) != -1) {
+                        (void) read(fd, lwpname, sizeof (lwpname));
+                        lwpname[THREAD_NAME_MAX - 1] = '\0';
+                        (void) close(fd);
+                }
+
+                free(path);
+
+                if (f->next != NULL)
+                        (void) printf("%-*s", width, lwpname);
+                else
+                        (void) printf("%s", lwpname);
+                break;
+        }
         case F_NLWP:
                 (void) printf("%*d", width, psinfo->pr_nlwp + psinfo->pr_nzomb);
                 break;
         case F_OPRI:
                 if (zombie_lwp)