diff options
author | dyson <dyson@FreeBSD.org> | 1997-12-05 07:33:40 +0000 |
---|---|---|
committer | dyson <dyson@FreeBSD.org> | 1997-12-05 07:33:40 +0000 |
commit | e09d7daa420c02576b9d742d40a5c7563baba7ca (patch) | |
tree | d913c97a6c0398a8af456775dd95f1f77e960ebd /bin | |
parent | b1d65d1edcac03a0c78eea5d6379ca0623f88a62 (diff) | |
download | FreeBSD-src-e09d7daa420c02576b9d742d40a5c7563baba7ca.zip FreeBSD-src-e09d7daa420c02576b9d742d40a5c7563baba7ca.tar.gz |
Add an option to building PS, so that the upages are explicitly paged in only
for users who are root, or in group wheel. This is useful on large timesharing
systems where a PS command can cause the system to grind to a halt. The
ability to get the information isn't diminished for those who really need the
additional detail (administrators.) Normal users won't see any difference unless
the processes are swapped out. The "really get it mode" is invoked by the
use of an additional flag in the command string "-f". New/old behavior is
selectable with a compile option.
PR: 5196
Submitted by: Matt Dillon <dillon@best.net>
Diffstat (limited to 'bin')
-rw-r--r-- | bin/ps/Makefile | 10 | ||||
-rw-r--r-- | bin/ps/ps.c | 47 |
2 files changed, 44 insertions, 13 deletions
diff --git a/bin/ps/Makefile b/bin/ps/Makefile index 8d797bc..4e8d954 100644 --- a/bin/ps/Makefile +++ b/bin/ps/Makefile @@ -1,9 +1,15 @@ -# $Id: Makefile,v 1.9 1997/08/11 02:36:09 steve Exp $ +# $Id: Makefile,v 1.10 1997/08/13 17:35:00 steve Exp $ # @(#)Makefile 8.1 (Berkeley) 6/2/93 PROG= ps SRCS= fmt.c keyword.c nlist.c print.c ps.c -CFLAGS+=-I${.CURDIR}/../../sys +# +# To support "lazy" ps for non root/wheel users +# add -DLAZY_PS to the cflags. This helps +# keep ps from being an unnecessary load +# on large systems. +# +CFLAGS+=-I${.CURDIR}/../../sys -DLAZY_PS DPADD= ${LIBM} ${LIBKVM} LDADD= -lm -lkvm BINGRP= kmem diff --git a/bin/ps/ps.c b/bin/ps/ps.c index c854e8e..091a97e 100644 --- a/bin/ps/ps.c +++ b/bin/ps/ps.c @@ -30,7 +30,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: ps.c,v 1.20 1997/06/06 06:40:06 charnier Exp $ + * $Id: ps.c,v 1.21 1997/08/03 08:25:01 peter Exp $ */ #ifndef lint @@ -79,6 +79,11 @@ int termwidth; /* width of screen (0 == infinity) */ int totwidth; /* calculated width of requested variables */ static int needuser, needcomm, needenv; +#if defined(LAZY_PS) +static int forceuread=0; +#else +static int forceuread=1; +#endif enum sort { DEFAULT, SORTMEM, SORTCPU } sortby = DEFAULT; @@ -137,7 +142,11 @@ main(argc, argv) ttydev = NODEV; memf = nlistf = swapf = NULL; while ((ch = getopt(argc, argv, +#if defined(LAZY_PS) + "aCcfeghjLlM:mN:O:o:p:rSTt:U:uvW:wx")) != -1) +#else "aCceghjLlM:mN:O:o:p:rSTt:U:uvW:wx")) != -1) +#endif switch((char)ch) { case 'a': all = 1; @@ -189,6 +198,12 @@ main(argc, argv) parsefmt(optarg); fmt = 1; break; +#if defined(LAZY_PS) + case 'f': + if (getuid() == 0 || getgid() == 0) + forceuread = 1; + break; +#endif case 'p': pid = atol(optarg); xflg = 1; @@ -430,6 +445,8 @@ fmt(fn, ki, comm, maxlen) return (s); } +#define UREADOK(ki) (forceuread || (KI_PROC(ki)->p_flag & P_INMEM)) + static void saveuser(ki) KINFO *ki; @@ -439,7 +456,7 @@ saveuser(ki) struct user *u_addr = (struct user *)USRSTACK; usp = &ki->ki_u; - if (kvm_uread(kd, KI_PROC(ki), (unsigned long)&u_addr->u_stats, + if (UREADOK(ki) && kvm_uread(kd, KI_PROC(ki), (unsigned long)&u_addr->u_stats, (char *)&pstats, sizeof(pstats)) == sizeof(pstats)) { /* * The u-area might be swapped out, and we can't get @@ -456,15 +473,23 @@ saveuser(ki) /* * save arguments if needed */ - if (needcomm) - ki->ki_args = fmt(kvm_getargv, ki, KI_PROC(ki)->p_comm, - MAXCOMLEN); - else - ki->ki_args = NULL; - if (needenv) - ki->ki_env = fmt(kvm_getenvv, ki, (char *)NULL, 0); - else - ki->ki_env = NULL; + if (needcomm && UREADOK(ki)) { + ki->ki_args = fmt(kvm_getargv, ki, KI_PROC(ki)->p_comm, + MAXCOMLEN); + } else if (needcomm) { + ki->ki_args = malloc(strlen(KI_PROC(ki)->p_comm) + 3); + sprintf(ki->ki_args, "(%s)", KI_PROC(ki)->p_comm); + } else { + ki->ki_args = NULL; + } + if (needenv && UREADOK(ki)) { + ki->ki_env = fmt(kvm_getenvv, ki, (char *)NULL, 0); + } else if (needenv) { + ki->ki_env = malloc(3); + strcpy(ki->ki_env, "()"); + } else { + ki->ki_env = NULL; + } } static int |