summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Levon <john.levon@joyent.com>2018-08-29 09:57:13 +0000
committerJohn Levon <john.levon@joyent.com>2018-08-29 09:57:13 +0000
commit52b14f3dd47c563098560bbf6fca5bcf21c307a5 (patch)
treec374bf36385a308351a088a318065622b4d8d331
parenta6fca367a038e96276893a1a531939076e11c419 (diff)
downloadillumos-joyent-52b14f3dd47c563098560bbf6fca5bcf21c307a5.tar.gz
ps fixes
-rw-r--r--usr/src/cmd/ps/ps.c56
-rw-r--r--usr/src/man/man1/ps.131
2 files changed, 44 insertions, 43 deletions
diff --git a/usr/src/cmd/ps/ps.c b/usr/src/cmd/ps/ps.c
index 9aa8c05a6e..7ea8bd4f0d 100644
--- a/usr/src/cmd/ps/ps.c
+++ b/usr/src/cmd/ps/ps.c
@@ -178,7 +178,7 @@ static struct def_field fname[] = {
{ "sid", "SID", 5, 5 },
{ "psr", "PSR", 3, 2 },
{ "lwp", "LWP", 6, 2 },
- { "lname", "LNAME", 32, 8 },
+ { "lwpname", "LWPNAME", 32, 8 },
{ "nlwp", "NLWP", 4, 2 },
{ "opri", "PRI", 3, 2 },
{ "pri", "PRI", 3, 2 },
@@ -813,6 +813,7 @@ stdmain(int argc, char **argv)
(void) printf("%-*s",
f->width, f->header);
break;
+ case F_LWPNAME:
case F_FNAME:
case F_COMM:
case F_ARGS:
@@ -861,7 +862,7 @@ stdmain(int argc, char **argv)
(void) printf(" %*s %*s", pidwidth, "PGID",
pidwidth, "SID");
if (Lflg)
- (void) printf(" LWP LNAME");
+ (void) printf(" LWP");
if (Pflg)
(void) printf(" PSR");
if (Lflg && fflg)
@@ -1188,7 +1189,8 @@ parse_format(char *arg)
}
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;
}
@@ -1362,26 +1364,6 @@ prfind(int found, psinfo_t *psinfo, char **tpp)
return (1);
}
-static void
-get_lwpname(psinfo_t *psinfo, char *buf, size_t bufsize)
-{
- char *path = NULL;
- int fd;
-
- buf[0] = '\0';
-
- if (asprintf(&path, "/proc/%d/lwp/%d/lwpname", (int)psinfo->pr_pid,
- (int)psinfo->pr_lwp.pr_lwpid) == -1)
- return;
-
- if ((fd = open(path, O_RDONLY)) != -1) {
- (void) read(fd, buf, bufsize);
- (void) close(fd);
- }
-
- free(path);
-}
-
/*
* Print info about the process.
*/
@@ -1487,14 +1469,8 @@ prcom(psinfo_t *psinfo, char *ttyp)
(void) printf(" %*d", pidwidth,
(int)psinfo->pr_sid); /* SID */
}
- if (Lflg) {
- char lwpname[THREAD_NAME_MAX] = "";
-
- get_lwpname(psinfo, lwpname, sizeof (lwpname));
-
- (void) printf(" %5d %8s", (int)psinfo->pr_lwp.pr_lwpid,
- lwpname); /* LWP */
- }
+ if (Lflg)
+ (void) printf(" %5d", (int)psinfo->pr_lwp.pr_lwpid); /* LWP */
if (Pflg) {
if (psinfo->pr_lwp.pr_bindpro == PBIND_NONE) /* PSR */
(void) printf(" -");
@@ -1792,8 +1768,22 @@ print_field(psinfo_t *psinfo, struct field *f, const char *ttyp)
break;
case F_LWPNAME: {
char lwpname[THREAD_NAME_MAX] = "";
- get_lwpname(psinfo, lwpname, sizeof (lwpname));
- (void) printf("%*s", width, lwpname);
+ char *path = NULL;
+ int fd;
+
+ if (asprintf(&path, "/proc/%d/lwp/%d/lwpname", (int)psinfo->pr_pid,
+ (int)psinfo->pr_lwp.pr_lwpid) != -1 &&
+ (fd = open(path, O_RDONLY)) != -1) {
+ (void) read(fd, lwpname, sizeof (lwpname));
+ (void) close(fd);
+ }
+
+ free(path);
+
+ if (f->next != NULL)
+ (void) printf("%-*s", width, lwpname);
+ else
+ (void) printf("%s", lwpname);
break;
}
case F_NLWP:
diff --git a/usr/src/man/man1/ps.1 b/usr/src/man/man1/ps.1
index afdda2f8ef..51b1942703 100644
--- a/usr/src/man/man1/ps.1
+++ b/usr/src/man/man1/ps.1
@@ -44,9 +44,9 @@
.\" Portions Copyright (c) 1992, X/Open Company Limited All Rights Reserved
.\" Copyright (c) 2009, Sun Microsystems, Inc. All Rights Reserved
.\" Copyright (c) 2013 Gary Mills
-.\" Copyright (c) 2017, Joyent, Inc.
+.\" Copyright (c) 2018, Joyent, Inc.
.\"
-.TH PS 1 "Jun 13, 2017"
+.TH PS 1 "August 22, 2018"
.SH NAME
ps \- report process status
.SH SYNOPSIS
@@ -1052,6 +1052,16 @@ one line to be printed for each lwp in the process.
.sp
.ne 2
.na
+\fB\fBlwpname\fR\fR
+.ad
+.RS 11n
+The name of the lwp, if set. Requesting this formatting option causes
+one line to be printed for each lwp in the process.
+.RE
+
+.sp
+.ne 2
+.na
\fB\fBnlwp\fR\fR
.ad
.RS 11n
@@ -1176,8 +1186,8 @@ The data model of the process, printed in the same manner as via
.sp
.LP
-Only \fBcomm\fR and \fBargs\fR are allowed to contain blank characters; all
-others, including the Solaris implementation variables, are not.
+Only \fBcomm\fR, \fBlwpname\fR, and \fBargs\fR are allowed to contain blank
+characters; all others, including the Solaris implementation variables, are not.
.sp
.LP
The following table specifies the default header to be used in the POSIX locale
@@ -1224,12 +1234,13 @@ fname COMMAND rss RSS
gid GID ruid RUID
lgrp LGRP s S
lwp LWP sid SID
-nlwp NLWP stime STIME
-opri PRI taskid TASKID
-osz SZ uid UID
-pmem %MEM wchan WCHAN
-pri PRI zone ZONE
-ctid CTID zoneid ZONEID
+lwpname LWPNAME stime STIME
+nlwp NLWP taskid TASKID
+opri PRI uid UID
+osz SZ wchan WCHAN
+pmem %MEM zone ZONE
+pri PRI zoneid ZONEID
+ctid CTID
.TE
.SH EXAMPLES