Deleted Added
full compact
machine.c (131628) machine.c (131829)
1/*
2 * top - a top users display for Unix
3 *
4 * SYNOPSIS: For FreeBSD-2.x and later
5 *
6 * DESCRIPTION:
7 * Originally written for BSD4.4 system by Christos Zoulas.
8 * Ported to FreeBSD 2.x by Steven Wallace && Wolfram Schneider

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

15 *
16 * LIBS: -lkvm
17 *
18 * AUTHOR: Christos Zoulas <christos@ee.cornell.edu>
19 * Steven Wallace <swallace@freebsd.org>
20 * Wolfram Schneider <wosch@FreeBSD.org>
21 * Thomas Moestl <tmoestl@gmx.net>
22 *
1/*
2 * top - a top users display for Unix
3 *
4 * SYNOPSIS: For FreeBSD-2.x and later
5 *
6 * DESCRIPTION:
7 * Originally written for BSD4.4 system by Christos Zoulas.
8 * Ported to FreeBSD 2.x by Steven Wallace && Wolfram Schneider

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

15 *
16 * LIBS: -lkvm
17 *
18 * AUTHOR: Christos Zoulas <christos@ee.cornell.edu>
19 * Steven Wallace <swallace@freebsd.org>
20 * Wolfram Schneider <wosch@FreeBSD.org>
21 * Thomas Moestl <tmoestl@gmx.net>
22 *
23 * $FreeBSD: head/usr.bin/top/machine.c 131628 2004-07-05 14:55:58Z des $
23 * $FreeBSD: head/usr.bin/top/machine.c 131829 2004-07-08 16:45:55Z keramida $
24 */
25
26#include <sys/param.h>
27#include <sys/errno.h>
28#include <sys/file.h>
29#include <sys/proc.h>
30#include <sys/resource.h>
31#include <sys/rtprio.h>

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

200/* define pagetok in terms of pageshift */
201
202#define pagetok(size) ((size) << pageshift)
203
204/* useful externals */
205long percentages();
206
207#ifdef ORDER
24 */
25
26#include <sys/param.h>
27#include <sys/errno.h>
28#include <sys/file.h>
29#include <sys/proc.h>
30#include <sys/resource.h>
31#include <sys/rtprio.h>

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

200/* define pagetok in terms of pageshift */
201
202#define pagetok(size) ((size) << pageshift)
203
204/* useful externals */
205long percentages();
206
207#ifdef ORDER
208/* sorting orders. first is default */
209char *ordernames[] = {
208/*
209 * Sorting orders. One vector per display mode.
210 * The first element is the default for each mode.
211 */
212char *proc_ordernames[] = {
210 "cpu", "size", "res", "time", "pri", NULL
211};
213 "cpu", "size", "res", "time", "pri", NULL
214};
215char *io_ordernames[] = {
216 "total", "read", "write", "fault", NULL
217};
212#endif
213
214int
215machine_init(struct statics *statics)
216{
217 int pagesize;
218 size_t modelen;
219 struct passwd *pw;

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

260 pageshift -= LOG1024;
261
262 /* fill in the statics information */
263 statics->procstate_names = procstatenames;
264 statics->cpustate_names = cpustatenames;
265 statics->memory_names = memorynames;
266 statics->swap_names = swapnames;
267#ifdef ORDER
218#endif
219
220int
221machine_init(struct statics *statics)
222{
223 int pagesize;
224 size_t modelen;
225 struct passwd *pw;

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

266 pageshift -= LOG1024;
267
268 /* fill in the statics information */
269 statics->procstate_names = procstatenames;
270 statics->cpustate_names = cpustatenames;
271 statics->memory_names = memorynames;
272 statics->swap_names = swapnames;
273#ifdef ORDER
268 statics->order_names = ordernames;
274 switch (displaymode) {
275 case DISP_IO:
276 statics->order_names = io_ordernames;
277 break;
278 case DISP_CPU:
279 default:
280 statics->order_names = proc_ordernames;
281 break;
282 }
269#endif
270
271 /* all done! */
272 return (0);
273}
274
275char *
276format_header(char *uname_field)

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

912 ORDERKEY_STATE(p1, p2);
913 ORDERKEY_RSSIZE(p1, p2);
914 ORDERKEY_MEM(p1, p2);
915
916 return (0);
917}
918#endif
919
283#endif
284
285 /* all done! */
286 return (0);
287}
288
289char *
290format_header(char *uname_field)

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

926 ORDERKEY_STATE(p1, p2);
927 ORDERKEY_RSSIZE(p1, p2);
928 ORDERKEY_MEM(p1, p2);
929
930 return (0);
931}
932#endif
933
934/* compare_io - the comparison function for sorting by total io */
935
920int
936int
937#ifdef ORDER
938compare_iototal(void *arg1, void *arg2)
939#else
921io_compare(void *arg1, void *arg2)
940io_compare(void *arg1, void *arg2)
941#endif
922{
923 struct kinfo_proc *p1 = *(struct kinfo_proc **)arg1;
924 struct kinfo_proc *p2 = *(struct kinfo_proc **)arg2;
925
926 return (get_io_total(p2) - get_io_total(p1));
927}
942{
943 struct kinfo_proc *p1 = *(struct kinfo_proc **)arg1;
944 struct kinfo_proc *p2 = *(struct kinfo_proc **)arg2;
945
946 return (get_io_total(p2) - get_io_total(p1));
947}
948
949#ifdef ORDER
950/* io compare routines */
951int compare_ioread(), compare_iowrite(), compare_iofault();
952
953int (*io_compares[])() = {
954 compare_iototal,
955 compare_ioread,
956 compare_iowrite,
957 compare_iofault,
958 NULL
959};
960
961int
962compare_ioread(void *arg1, void *arg2)
963{
964 struct kinfo_proc *p1 = *(struct kinfo_proc **)arg1;
965 struct kinfo_proc *p2 = *(struct kinfo_proc **)arg2;
966 long dummy, inp1, inp2;
967
968 (void) get_io_stats(p1, &inp1, &dummy, &dummy);
969 (void) get_io_stats(p2, &inp2, &dummy, &dummy);
970
971 return (inp2 - inp1);
972}
973
974int
975compare_iowrite(void *arg1, void *arg2)
976{
977 struct kinfo_proc *p1 = *(struct kinfo_proc **)arg1;
978 struct kinfo_proc *p2 = *(struct kinfo_proc **)arg2;
979 long dummy, oup1, oup2;
980
981 (void) get_io_stats(p1, &dummy, &oup1, &dummy);
982 (void) get_io_stats(p2, &dummy, &oup2, &dummy);
983
984 return (oup2 - oup1);
985}
986
987int
988compare_iofault(void *arg1, void *arg2)
989{
990 struct kinfo_proc *p1 = *(struct kinfo_proc **)arg1;
991 struct kinfo_proc *p2 = *(struct kinfo_proc **)arg2;
992 long dummy, flp1, flp2;
993
994 (void) get_io_stats(p1, &dummy, &dummy, &flp1);
995 (void) get_io_stats(p2, &dummy, &dummy, &flp2);
996
997 return (flp2 - flp1);
998}
999
1000#endif /* ORDER */
1001
928/*
929 * proc_owner(pid) - returns the uid that owns process "pid", or -1 if
930 * the process does not exist.
931 * It is EXTREMLY IMPORTANT that this function work correctly.
932 * If top runs setuid root (as in SVR4), then this function
933 * is the only thing that stands in the way of a serious
934 * security problem. It validates requests for the "kill"
935 * and "renice" commands.

--- 41 unchanged lines hidden ---
1002/*
1003 * proc_owner(pid) - returns the uid that owns process "pid", or -1 if
1004 * the process does not exist.
1005 * It is EXTREMLY IMPORTANT that this function work correctly.
1006 * If top runs setuid root (as in SVR4), then this function
1007 * is the only thing that stands in the way of a serious
1008 * security problem. It validates requests for the "kill"
1009 * and "renice" commands.

--- 41 unchanged lines hidden ---