procstat.c (249685) | procstat.c (249686) |
---|---|
1/*- 2 * Copyright (c) 2007, 2011 Robert N. M. Watson 3 * 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 --- 9 unchanged lines hidden (view full) --- 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * | 1/*- 2 * Copyright (c) 2007, 2011 Robert N. M. Watson 3 * 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 --- 9 unchanged lines hidden (view full) --- 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * |
26 * $FreeBSD: head/usr.bin/procstat/procstat.c 249685 2013-04-20 08:19:06Z trociny $ | 26 * $FreeBSD: head/usr.bin/procstat/procstat.c 249686 2013-04-20 08:22:09Z trociny $ |
27 */ 28 29#include <sys/param.h> 30#include <sys/sysctl.h> 31#include <sys/user.h> 32 33#include <err.h> 34#include <libprocstat.h> --- 10 unchanged lines hidden (view full) --- 45 46static void 47usage(void) 48{ 49 50 fprintf(stderr, "usage: procstat [-h] [-C] [-M core] [-N system] " 51 "[-w interval] \n"); 52 fprintf(stderr, " [-b | -c | -e | -f | -i | -j | -k | " | 27 */ 28 29#include <sys/param.h> 30#include <sys/sysctl.h> 31#include <sys/user.h> 32 33#include <err.h> 34#include <libprocstat.h> --- 10 unchanged lines hidden (view full) --- 45 46static void 47usage(void) 48{ 49 50 fprintf(stderr, "usage: procstat [-h] [-C] [-M core] [-N system] " 51 "[-w interval] \n"); 52 fprintf(stderr, " [-b | -c | -e | -f | -i | -j | -k | " |
53 "-l | -s | -t | -v | -x] [-a | pid ...]\n"); | 53 "-l | -s | -t | -v | -x] [-a | pid | core ...]\n"); |
54 exit(EX_USAGE); 55} 56 57static void 58procstat(struct procstat *prstat, struct kinfo_proc *kipp) 59{ 60 61 if (bflag) --- 49 unchanged lines hidden (view full) --- 111} 112 113int 114main(int argc, char *argv[]) 115{ 116 int ch, interval, tmp; 117 int i; 118 struct kinfo_proc *p; | 54 exit(EX_USAGE); 55} 56 57static void 58procstat(struct procstat *prstat, struct kinfo_proc *kipp) 59{ 60 61 if (bflag) --- 49 unchanged lines hidden (view full) --- 111} 112 113int 114main(int argc, char *argv[]) 115{ 116 int ch, interval, tmp; 117 int i; 118 struct kinfo_proc *p; |
119 struct procstat *prstat; | 119 struct procstat *prstat, *cprstat; |
120 long l; 121 pid_t pid; 122 char *dummy; 123 char *nlistf, *memf; 124 int cnt; 125 126 interval = 0; 127 memf = nlistf = NULL; --- 122 unchanged lines hidden (view full) --- 250 251 /* Suppress header after first process. */ 252 hflag = 1; 253 } 254 procstat_freeprocs(prstat, p); 255 } 256 for (i = 0; i < argc; i++) { 257 l = strtol(argv[i], &dummy, 10); | 120 long l; 121 pid_t pid; 122 char *dummy; 123 char *nlistf, *memf; 124 int cnt; 125 126 interval = 0; 127 memf = nlistf = NULL; --- 122 unchanged lines hidden (view full) --- 250 251 /* Suppress header after first process. */ 252 hflag = 1; 253 } 254 procstat_freeprocs(prstat, p); 255 } 256 for (i = 0; i < argc; i++) { 257 l = strtol(argv[i], &dummy, 10); |
258 if (*dummy != '\0') 259 usage(); 260 if (l < 0) 261 usage(); 262 pid = l; | 258 if (*dummy == '\0') { 259 if (l < 0) 260 usage(); 261 pid = l; |
263 | 262 |
264 p = procstat_getprocs(prstat, KERN_PROC_PID, pid, &cnt); 265 if (p == NULL) 266 errx(1, "procstat_getprocs()"); 267 if (cnt != 0) 268 procstat(prstat, p); 269 procstat_freeprocs(prstat, p); 270 | 263 p = procstat_getprocs(prstat, KERN_PROC_PID, pid, &cnt); 264 if (p == NULL) 265 errx(1, "procstat_getprocs()"); 266 if (cnt != 0) 267 procstat(prstat, p); 268 procstat_freeprocs(prstat, p); 269 } else { 270 cprstat = procstat_open_core(argv[i]); 271 if (cprstat == NULL) { 272 warnx("procstat_open()"); 273 continue; 274 } 275 p = procstat_getprocs(cprstat, KERN_PROC_PID, 276 -1, &cnt); 277 if (p == NULL) 278 errx(1, "procstat_getprocs()"); 279 if (cnt != 0) 280 procstat(cprstat, p); 281 procstat_freeprocs(cprstat, p); 282 procstat_close(cprstat); 283 } |
271 /* Suppress header after first process. */ 272 hflag = 1; 273 } 274 if (interval) 275 sleep(interval); 276 } while (interval); 277 procstat_close(prstat); 278 exit(0); 279} | 284 /* Suppress header after first process. */ 285 hflag = 1; 286 } 287 if (interval) 288 sleep(interval); 289 } while (interval); 290 procstat_close(prstat); 291 exit(0); 292} |