summaryrefslogtreecommitdiffstats
path: root/bin/ps
diff options
context:
space:
mode:
authortjr <tjr@FreeBSD.org>2002-06-04 10:20:10 +0000
committertjr <tjr@FreeBSD.org>2002-06-04 10:20:10 +0000
commitb3775d9e40a35c9a29987626474b49176f40362a (patch)
tree53988ee5729bf699707c493d2003f4605612b408 /bin/ps
parentc6efb66343b00c4a373073a02f93f09959f44c54 (diff)
downloadFreeBSD-src-b3775d9e40a35c9a29987626474b49176f40362a.zip
FreeBSD-src-b3775d9e40a35c9a29987626474b49176f40362a.tar.gz
Respect setting of the COLUMNS environment variable (SUSv3)
Diffstat (limited to 'bin/ps')
-rw-r--r--bin/ps/ps.110
-rw-r--r--bin/ps/ps.c5
2 files changed, 14 insertions, 1 deletions
diff --git a/bin/ps/ps.1 b/bin/ps/ps.1
index 52d68ec..8e2deba 100644
--- a/bin/ps/ps.1
+++ b/bin/ps/ps.1
@@ -506,6 +506,16 @@ wait channel (as a symbolic name)
.It xstat
exit or stop status (valid only for stopped or zombie process)
.El
+.Sh ENVIRONMENT
+The following environment variables affect the execution of
+.Nm :
+.Bl -tag -width ".Ev COLUMNS"
+.It Ev COLUMNS
+If set, specifies the user's preferred output width in column positions.
+By default,
+.Nm
+attempts to automatically determine the terminal width.
+.El
.Sh FILES
.Bl -tag -width /var/db/kvm_kernel.db -compact
.It Pa /dev/kmem
diff --git a/bin/ps/ps.c b/bin/ps/ps.c
index dbc9a14..be31a92 100644
--- a/bin/ps/ps.c
+++ b/bin/ps/ps.c
@@ -123,12 +123,15 @@ main(int argc, char *argv[])
uid_t *uids;
int all, ch, flag, i, _fmt, lineno, nentries, dropgid;
int prtheader, wflag, what, xflg, uid, nuids;
+ char *cols;
char errbuf[_POSIX2_LINE_MAX];
const char *nlistf, *memf;
(void) setlocale(LC_ALL, "");
- if ((ioctl(STDOUT_FILENO, TIOCGWINSZ, (char *)&ws) == -1 &&
+ if ((cols = getenv("COLUMNS")) != NULL && *cols != '\0')
+ termwidth = atoi(cols);
+ else if ((ioctl(STDOUT_FILENO, TIOCGWINSZ, (char *)&ws) == -1 &&
ioctl(STDERR_FILENO, TIOCGWINSZ, (char *)&ws) == -1 &&
ioctl(STDIN_FILENO, TIOCGWINSZ, (char *)&ws) == -1) ||
ws.ws_col == 0)
OpenPOWER on IntegriCloud