ps.c (27856) | ps.c (31552) |
---|---|
1/*- 2 * Copyright (c) 1990, 1993, 1994 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 16 unchanged lines hidden (view full) --- 25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * | 1/*- 2 * Copyright (c) 1990, 1993, 1994 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 16 unchanged lines hidden (view full) --- 25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * |
33 * $Id: ps.c,v 1.20 1997/06/06 06:40:06 charnier Exp $ | 33 * $Id: ps.c,v 1.21 1997/08/03 08:25:01 peter Exp $ |
34 */ 35 36#ifndef lint 37static char const copyright[] = 38"@(#) Copyright (c) 1990, 1993, 1994\n\ 39 The Regents of the University of California. All rights reserved.\n"; 40#endif /* not lint */ 41 --- 32 unchanged lines hidden (view full) --- 74int eval; /* exit value */ 75int cflag; /* -c */ 76int rawcpu; /* -C */ 77int sumrusage; /* -S */ 78int termwidth; /* width of screen (0 == infinity) */ 79int totwidth; /* calculated width of requested variables */ 80 81static int needuser, needcomm, needenv; | 34 */ 35 36#ifndef lint 37static char const copyright[] = 38"@(#) Copyright (c) 1990, 1993, 1994\n\ 39 The Regents of the University of California. All rights reserved.\n"; 40#endif /* not lint */ 41 --- 32 unchanged lines hidden (view full) --- 74int eval; /* exit value */ 75int cflag; /* -c */ 76int rawcpu; /* -C */ 77int sumrusage; /* -S */ 78int termwidth; /* width of screen (0 == infinity) */ 79int totwidth; /* calculated width of requested variables */ 80 81static int needuser, needcomm, needenv; |
82#if defined(LAZY_PS) 83static int forceuread=0; 84#else 85static int forceuread=1; 86#endif |
|
82 83enum sort { DEFAULT, SORTMEM, SORTCPU } sortby = DEFAULT; 84 85static char *fmt __P((char **(*)(kvm_t *, const struct kinfo_proc *, int), 86 KINFO *, char *, int)); 87static char *kludge_oldps_options __P((char *)); 88static int pscomp __P((const void *, const void *)); 89static void saveuser __P((KINFO *)); --- 42 unchanged lines hidden (view full) --- 132 argv[1] = kludge_oldps_options(argv[1]); 133 134 all = fmt = prtheader = wflag = xflg = 0; 135 pid = -1; 136 uid = (uid_t) -1; 137 ttydev = NODEV; 138 memf = nlistf = swapf = NULL; 139 while ((ch = getopt(argc, argv, | 87 88enum sort { DEFAULT, SORTMEM, SORTCPU } sortby = DEFAULT; 89 90static char *fmt __P((char **(*)(kvm_t *, const struct kinfo_proc *, int), 91 KINFO *, char *, int)); 92static char *kludge_oldps_options __P((char *)); 93static int pscomp __P((const void *, const void *)); 94static void saveuser __P((KINFO *)); --- 42 unchanged lines hidden (view full) --- 137 argv[1] = kludge_oldps_options(argv[1]); 138 139 all = fmt = prtheader = wflag = xflg = 0; 140 pid = -1; 141 uid = (uid_t) -1; 142 ttydev = NODEV; 143 memf = nlistf = swapf = NULL; 144 while ((ch = getopt(argc, argv, |
145#if defined(LAZY_PS) 146 "aCcfeghjLlM:mN:O:o:p:rSTt:U:uvW:wx")) != -1) 147#else |
|
140 "aCceghjLlM:mN:O:o:p:rSTt:U:uvW:wx")) != -1) | 148 "aCceghjLlM:mN:O:o:p:rSTt:U:uvW:wx")) != -1) |
149#endif |
|
141 switch((char)ch) { 142 case 'a': 143 all = 1; 144 break; 145 case 'C': 146 rawcpu = 1; 147 break; 148 case 'c': --- 35 unchanged lines hidden (view full) --- 184 parsefmt(o2); 185 o1[0] = o2[0] = '\0'; 186 fmt = 1; 187 break; 188 case 'o': 189 parsefmt(optarg); 190 fmt = 1; 191 break; | 150 switch((char)ch) { 151 case 'a': 152 all = 1; 153 break; 154 case 'C': 155 rawcpu = 1; 156 break; 157 case 'c': --- 35 unchanged lines hidden (view full) --- 193 parsefmt(o2); 194 o1[0] = o2[0] = '\0'; 195 fmt = 1; 196 break; 197 case 'o': 198 parsefmt(optarg); 199 fmt = 1; 200 break; |
201#if defined(LAZY_PS) 202 case 'f': 203 if (getuid() == 0 || getgid() == 0) 204 forceuread = 1; 205 break; 206#endif |
|
192 case 'p': 193 pid = atol(optarg); 194 xflg = 1; 195 break; 196 case 'r': 197 sortby = SORTCPU; 198 break; 199 case 'S': --- 225 unchanged lines hidden (view full) --- 425 char *s; 426 427 if ((s = 428 fmt_argv((*fn)(kd, ki->ki_p, termwidth), comm, maxlen)) == NULL) 429 err(1, NULL); 430 return (s); 431} 432 | 207 case 'p': 208 pid = atol(optarg); 209 xflg = 1; 210 break; 211 case 'r': 212 sortby = SORTCPU; 213 break; 214 case 'S': --- 225 unchanged lines hidden (view full) --- 440 char *s; 441 442 if ((s = 443 fmt_argv((*fn)(kd, ki->ki_p, termwidth), comm, maxlen)) == NULL) 444 err(1, NULL); 445 return (s); 446} 447 |
448#define UREADOK(ki) (forceuread || (KI_PROC(ki)->p_flag & P_INMEM)) 449 |
|
433static void 434saveuser(ki) 435 KINFO *ki; 436{ 437 struct pstats pstats; 438 struct usave *usp; 439 struct user *u_addr = (struct user *)USRSTACK; 440 441 usp = &ki->ki_u; | 450static void 451saveuser(ki) 452 KINFO *ki; 453{ 454 struct pstats pstats; 455 struct usave *usp; 456 struct user *u_addr = (struct user *)USRSTACK; 457 458 usp = &ki->ki_u; |
442 if (kvm_uread(kd, KI_PROC(ki), (unsigned long)&u_addr->u_stats, | 459 if (UREADOK(ki) && kvm_uread(kd, KI_PROC(ki), (unsigned long)&u_addr->u_stats, |
443 (char *)&pstats, sizeof(pstats)) == sizeof(pstats)) { 444 /* 445 * The u-area might be swapped out, and we can't get 446 * at it because we have a crashdump and no swap. 447 * If it's here fill in these fields, otherwise, just 448 * leave them 0. 449 */ 450 usp->u_start = pstats.p_start; 451 usp->u_ru = pstats.p_ru; 452 usp->u_cru = pstats.p_cru; 453 usp->u_valid = 1; 454 } else 455 usp->u_valid = 0; 456 /* 457 * save arguments if needed 458 */ | 460 (char *)&pstats, sizeof(pstats)) == sizeof(pstats)) { 461 /* 462 * The u-area might be swapped out, and we can't get 463 * at it because we have a crashdump and no swap. 464 * If it's here fill in these fields, otherwise, just 465 * leave them 0. 466 */ 467 usp->u_start = pstats.p_start; 468 usp->u_ru = pstats.p_ru; 469 usp->u_cru = pstats.p_cru; 470 usp->u_valid = 1; 471 } else 472 usp->u_valid = 0; 473 /* 474 * save arguments if needed 475 */ |
459 if (needcomm) 460 ki->ki_args = fmt(kvm_getargv, ki, KI_PROC(ki)->p_comm, 461 MAXCOMLEN); 462 else 463 ki->ki_args = NULL; 464 if (needenv) 465 ki->ki_env = fmt(kvm_getenvv, ki, (char *)NULL, 0); 466 else 467 ki->ki_env = NULL; | 476 if (needcomm && UREADOK(ki)) { 477 ki->ki_args = fmt(kvm_getargv, ki, KI_PROC(ki)->p_comm, 478 MAXCOMLEN); 479 } else if (needcomm) { 480 ki->ki_args = malloc(strlen(KI_PROC(ki)->p_comm) + 3); 481 sprintf(ki->ki_args, "(%s)", KI_PROC(ki)->p_comm); 482 } else { 483 ki->ki_args = NULL; 484 } 485 if (needenv && UREADOK(ki)) { 486 ki->ki_env = fmt(kvm_getenvv, ki, (char *)NULL, 0); 487 } else if (needenv) { 488 ki->ki_env = malloc(3); 489 strcpy(ki->ki_env, "()"); 490 } else { 491 ki->ki_env = NULL; 492 } |
468} 469 470static int 471pscomp(a, b) 472 const void *a, *b; 473{ 474 int i; 475#define VSIZE(k) (KI_EPROC(k)->e_vm.vm_dsize + KI_EPROC(k)->e_vm.vm_ssize + \ --- 83 unchanged lines hidden --- | 493} 494 495static int 496pscomp(a, b) 497 const void *a, *b; 498{ 499 int i; 500#define VSIZE(k) (KI_EPROC(k)->e_vm.vm_dsize + KI_EPROC(k)->e_vm.vm_ssize + \ --- 83 unchanged lines hidden --- |