Deleted Added
full compact
procstat.c (174199) procstat.c (176107)
1/*-
2 * Copyright (c) 2007 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 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 174199 2007-12-02 23:31:45Z rwatson $
26 * $FreeBSD: head/usr.bin/procstat/procstat.c 176107 2008-02-08 11:03:05Z dwmalone $
27 */
28
29#include <sys/types.h>
30#include <sys/sysctl.h>
31#include <sys/user.h>
32
33#include <err.h>
34#include <stdio.h>

--- 41 unchanged lines hidden (view full) ---

76/*
77 * Sort processes first by pid and then tid.
78 */
79static int
80kinfo_proc_compare(const void *a, const void *b)
81{
82 int i;
83
27 */
28
29#include <sys/types.h>
30#include <sys/sysctl.h>
31#include <sys/user.h>
32
33#include <err.h>
34#include <stdio.h>

--- 41 unchanged lines hidden (view full) ---

76/*
77 * Sort processes first by pid and then tid.
78 */
79static int
80kinfo_proc_compare(const void *a, const void *b)
81{
82 int i;
83
84 i = ((struct kinfo_proc *)a)->ki_pid -
85 ((struct kinfo_proc *)b)->ki_pid;
84 i = ((const struct kinfo_proc *)a)->ki_pid -
85 ((const struct kinfo_proc *)b)->ki_pid;
86 if (i != 0)
87 return (i);
86 if (i != 0)
87 return (i);
88 i = ((struct kinfo_proc *)a)->ki_tid -
89 ((struct kinfo_proc *)b)->ki_tid;
88 i = ((const struct kinfo_proc *)a)->ki_tid -
89 ((const struct kinfo_proc *)b)->ki_tid;
90 return (i);
91}
92
93void
94kinfo_proc_sort(struct kinfo_proc *kipp, int count)
95{
96
97 qsort(kipp, count, sizeof(*kipp), kinfo_proc_compare);
98}
99
100int
101main(int argc, char *argv[])
102{
90 return (i);
91}
92
93void
94kinfo_proc_sort(struct kinfo_proc *kipp, int count)
95{
96
97 qsort(kipp, count, sizeof(*kipp), kinfo_proc_compare);
98}
99
100int
101main(int argc, char *argv[])
102{
103 int ch, i, interval, name[4], tmp;
103 int ch, interval, name[4], tmp;
104 unsigned int i;
104 struct kinfo_proc *kipp;
105 size_t len;
106 long l;
107 pid_t pid;
108 char *dummy;
109
110 interval = 0;
111 while ((ch = getopt(argc, argv, "abcfkhstvw:")) != -1) {

--- 91 unchanged lines hidden (view full) ---

203 for (i = 0; i < len / sizeof(*kipp); i++) {
204 procstat(kipp[i].ki_pid, &kipp[i]);
205
206 /* Suppress header after first process. */
207 hflag = 1;
208 }
209 free(kipp);
210 }
105 struct kinfo_proc *kipp;
106 size_t len;
107 long l;
108 pid_t pid;
109 char *dummy;
110
111 interval = 0;
112 while ((ch = getopt(argc, argv, "abcfkhstvw:")) != -1) {

--- 91 unchanged lines hidden (view full) ---

204 for (i = 0; i < len / sizeof(*kipp); i++) {
205 procstat(kipp[i].ki_pid, &kipp[i]);
206
207 /* Suppress header after first process. */
208 hflag = 1;
209 }
210 free(kipp);
211 }
211 for (i = 0; i < argc; i++) {
212 for (i = 0; i < (unsigned int)argc; i++) {
212 l = strtol(argv[i], &dummy, 10);
213 if (*dummy != '\0')
214 usage();
215 if (l < 0)
216 usage();
217 pid = l;
218
219 name[0] = CTL_KERN;

--- 33 unchanged lines hidden ---
213 l = strtol(argv[i], &dummy, 10);
214 if (*dummy != '\0')
215 usage();
216 if (l < 0)
217 usage();
218 pid = l;
219
220 name[0] = CTL_KERN;

--- 33 unchanged lines hidden ---