#ifndef lint
-static char *sccsid = "@(#)ps.c 4.29 (Berkeley) %G%";
+static char *sccsid = "@(#)ps.c 4.30 (Berkeley) %G%";
#endif
/*
#include <nlist.h>
#include <pwd.h>
#include <sys/param.h>
+#include <sys/ioctl.h>
#include <sys/tty.h>
#include <sys/dir.h>
#include <sys/user.h>
int cmdstart;
int twidth;
+struct winsize win;
char *kmemf, *memf, *swapf, *nlistf;
int kmem, mem, swap = -1;
int rawcpu, sumcpu;
register char *ap;
int uid;
off_t procp;
+ int width;
- twidth = 80;
+ if (ioctl(0, TIOCGWINSZ, &win) == -1)
+ twidth = 80;
+ else
+ twidth = (win.ws_col == 0 ? 80 : win.ws_col);
argc--, argv++;
if (argc > 0) {
ap = argv[0];
vflg++;
break;
case 'w':
- if (twidth == 80)
+ if (twidth < 132)
twidth = 132;
else
twidth = BUFSIZ;
save();
}
}
+ width = twidth - cmdstart - 2;
+ if (width < 0)
+ width = 0;
qsort((char *) savcom, npr, sizeof(savcom[0]), pscomp);
for (i=0; i<npr; i++) {
register struct savcom *sp = &savcom[i];
static init = 0;
struct passwd *getpwent();
register struct nametable *n;
+ extern int _pw_stayopen;
/*
* find uid in hashed table; add it if not found.
switch (init) {
case 0:
setpwent();
+ _pw_stayopen = 1;
init = 1;
/* intentional fall-thru */
case 1: