Deleted Added
full compact
procstat.c (245530) procstat.c (250871)
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: stable/9/usr.bin/procstat/procstat.c 245530 2013-01-17 02:42:08Z mjg $
26 * $FreeBSD: stable/9/usr.bin/procstat/procstat.c 250871 2013-05-21 19:05:27Z 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)
54 exit(EX_USAGE);
55}
56
57static void
58procstat(struct procstat *prstat, struct kinfo_proc *kipp)
59{
60
61 if (bflag)
62 procstat_bin(kipp);
62 procstat_bin(prstat, kipp);
63 else if (cflag)
63 else if (cflag)
64 procstat_args(kipp);
64 procstat_args(prstat, kipp);
65 else if (eflag)
65 else if (eflag)
66 procstat_env(kipp);
66 procstat_env(prstat, kipp);
67 else if (fflag)
68 procstat_files(prstat, kipp);
69 else if (iflag)
70 procstat_sigs(prstat, kipp);
71 else if (jflag)
72 procstat_threads_sigs(prstat, kipp);
73 else if (kflag)
67 else if (fflag)
68 procstat_files(prstat, kipp);
69 else if (iflag)
70 procstat_sigs(prstat, kipp);
71 else if (jflag)
72 procstat_threads_sigs(prstat, kipp);
73 else if (kflag)
74 procstat_kstack(kipp, kflag);
74 procstat_kstack(prstat, kipp, kflag);
75 else if (lflag)
75 else if (lflag)
76 procstat_rlimit(kipp);
76 procstat_rlimit(prstat, kipp);
77 else if (sflag)
77 else if (sflag)
78 procstat_cred(kipp);
78 procstat_cred(prstat, kipp);
79 else if (tflag)
79 else if (tflag)
80 procstat_threads(kipp);
80 procstat_threads(prstat, kipp);
81 else if (vflag)
81 else if (vflag)
82 procstat_vm(kipp);
82 procstat_vm(prstat, kipp);
83 else if (xflag)
83 else if (xflag)
84 procstat_auxv(kipp);
84 procstat_auxv(prstat, kipp);
85 else
86 procstat_basic(kipp);
87}
88
89/*
90 * Sort processes first by pid and then tid.
91 */
92static int

--- 18 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;
85 else
86 procstat_basic(kipp);
87}
88
89/*
90 * Sort processes first by pid and then tid.
91 */
92static int

--- 18 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}