diff options
author | John Dyson <dyson@FreeBSD.org> | 1997-12-05 07:33:40 +0000 |
---|---|---|
committer | John Dyson <dyson@FreeBSD.org> | 1997-12-05 07:33:40 +0000 |
commit | 3ac5e95583e70eb01604b8976dfcde2ccfbd4d7d (patch) | |
tree | 3ebcbf045d371401624f5a70e7b64a831e1a3092 /bin/ps/ps.c | |
parent | 70111b90163c31900e33d610a0c83c44d0c3ce8f (diff) | |
download | src-3ac5e95583e70eb01604b8976dfcde2ccfbd4d7d.tar.gz src-3ac5e95583e70eb01604b8976dfcde2ccfbd4d7d.zip |
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>
Notes
Notes:
svn path=/head/; revision=31552
Diffstat (limited to 'bin/ps/ps.c')
-rw-r--r-- | bin/ps/ps.c | 47 |
1 files changed, 36 insertions, 11 deletions
diff --git a/bin/ps/ps.c b/bin/ps/ps.c index c854e8ecf95f..091a97e04442 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 |